我试着运行一个八度的MATLAB代码有一个MATLAB函数extractBetween
在倍频程中还不可用原始代码是
numbers = str2double(extractBetween(dirAndFileNames(:,2), 4, 5));
我试着用这个代码替换它。
numbers = str2double(substr(dirAndFileNames(:,2), 4, 2));
它适用于单个字符串,但不适用于单元格数组我尝试过其他与单元格数组一起工作的函数,如
strtrim
,strtrunc
我想提取末尾的数字,但是strtrunc
给出的结果与我想要的相反它给出了第一个字母。dirAndFilenames(:,2)
如下所示:debug> dirAndFileNames(:,2)
ans =
{
[1,1] = desktop.ini
[2,1] = trn01
[3,1] = trn02
[4,1] = trn03
[5,1] = trn04
[6,1] = trn05
[7,1] = trn06
[8,1] = trn07
[9,1] = trn08
[10,1] = trn09
[11,1] = trn10
}
最佳答案
正如@cris建议的那样,我得绕过去。
for i = 1:length(dirAndFileNames)
numbers{i} = str2double(substr(dirAndFileNames(i,2){1}, 4, 2))
end