![]() |
matlab的exist命令在循环语句中的问题
我要对一个文件夹中的全部文件进行处理,用了循环语句,但在用exist判断某文件是否存在(若存在进行其他处理)出错。简单程序如下:
clear; clc; for i = 1:1000; file2=['G:\datapressure\xicy2-0' num2str(i)]; %文件xicy2-01,xicy2-02....含有字符 if exist('file2','file')==2 %[COLOR="Red"] 因个别文件不存在[/COLOR],故用这个语句来判断,但整[COLOR="red"]个循环中exist('file2','file')的值全为0,下面语句不[/COLOR]执行 data_all2=importdata(file2); data2=data_all2.data; ....... end end 若用exist('G:\datapressure\xicy2-01','file') 当文件存在时值是2,不存在值为0。但有上千文件,不能手动处理。请教高手上面程序要怎样修改啊??或者,不用exist也行,只要能判断某文件是否存在,以便对存在文件进行处理就行。先谢了 |
回复: matlab的exist命令在循环语句中的问题
I think you should add the file extension. Your file path is not complete so the file can not be found, as a result, the returned value is 0 not 2 expected.
|
所有时间均为北京时间。现在的时间是 05:33。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.