-
Notifications
You must be signed in to change notification settings - Fork 71
/
PTstr2num.m
22 lines (19 loc) · 894 Bytes
/
PTstr2num.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function data = PTstr2num(str, numCols)
%% data = PTstr2num(str, numCols)
% data = PTstr2num(str, numCols)
% modified from:
% https://www.mathworks.com/company/newsletters/articles/tips-for-accelerating-matlab-performance.html
% ----------------------------------------------------------------------------------
% "THE BEER-WARE LICENSE" (Revision 42):
% <brian.white@queensu.ca> wrote this file. As long as you retain this notice you
% can do whatever you want with this stuff. If we meet some day, and you think
% this stuff is worth it, you can buy me a beer in return. -Brian White
% ----------------------------------------------------------------------------------
% faster alternative to str2num
str = char(str);
str(:,end+1) = ' ';
data = sscanf(str','%f');
if nargin>1 && ~isempty(numCols)
data = reshape(data,numCols,[])';
end
end