【发布时间】:2018-10-08 18:59:21
【问题描述】:
我目前有一个从 P0.01.mat-P10.mat 标记的 mat 文件列表,并且想获取所选 .mat 文件的数值。我目前所拥有的只是从 P1.mat 到 P10.mat。当我为一串 P0.01.mat 运行它时,它返回数字 1。
Files=dir(fullfile(datapath,'*.mat'));
numfiles=length(Files);
results=cell(numfiles,1);
for k = 1:numfiles
results{k}=Files(k).name; % lists all the names available
end
Ace=[results];
A=Ace(1); %selects the string
B = regexp(A,'\d*','Match'); %gets the numerals in the string
for ii= 1:length(B)
if ~isempty(B{ii})
Num(ii,1)=str2double(B{ii}(end));
else
Num(ii,1)=NaN;
end
end
Num
【问题讨论】: