Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何在MatLab中解决dir命令的不同输入?_Regex_Image_Matlab_Dir - Fatal编程技术网

Regex 如何在MatLab中解决dir命令的不同输入?

Regex 如何在MatLab中解决dir命令的不同输入?,regex,image,matlab,dir,Regex,Image,Matlab,Dir,我正在使用下面的MatLab代码从文件夹中读取图像 [folder1] = uigetdir(); f=dir(folder1); for k=1:size(f,1)-2 new_file=f(k+2).name; end [idx,idx]=sort(cellfun(@(x) str2num(char(regexp(x,'\d*','match'))),new_file)); filename1=new_file(idx); 此代码适用于名为“test_base1”、“test_b

我正在使用下面的MatLab代码从文件夹中读取图像

[folder1] = uigetdir();
f=dir(folder1);

for k=1:size(f,1)-2
    new_file=f(k+2).name;
end
[idx,idx]=sort(cellfun(@(x) str2num(char(regexp(x,'\d*','match'))),new_file));
filename1=new_file(idx);
此代码适用于名为“test_base1”、“test_base2”的文件夹中的图像

我面临一个错误,该表达式的输入不同

For file = {'test_30min1','test_30min10','test_30min2'};
它给出如下误差

??? Error using ==> cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.

我尝试在这个表达式中给出
regexp(x,'\w*','match')
和许多其他组合。我无法得到解决办法。我可以知道解决这个问题的方法吗?

这个错误专门指的是
cellfun
,而不是
regexp
,甚至告诉您如何修复它:“将'UniformOutput'设置为false。”查看
cellfun
的帮助<代码>cellfun(…,'UniformOutput',false)。嘿,当输入文件={test_1min}但不为文件={test_1min}工作时,它怎么会工作呢。。两种输入类型相同。只有输入中的元素会更改,但文件类型不会更改
str2num(char(regexp('test_1min','\d*','match'))
仅匹配一位数字:1
str2num(char(regexp('test_1min1','\d*','match'))
匹配两个:都是1。如果只想匹配文件名末尾的数字,请改用此regexp模式:
“\d*$”
。因此,在regexp中没有匹配两个数字的选项??“将'UniformOutput'设置为false是唯一的解决方案???嘿,'\d*$'正在工作…非常感谢