Problem with importdata with filename obtained two different ways
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am trying to open a data file which contains a number in the file name. As this number keeps changing, I want to come up with the file name using string concatenation. The string concatenation works fine and I get the file name. But, when I try to load the file (tried commands load and importdata) using the obtained file name, I get the error saying "??? Error using ==> importdata at 123 Unable to open file." If I explicitly give the file name then everything works fine. I compared the file name obtained using concatenation with that of actual file name and I get '1'. I am not sure what is going wrong. Here is the code
STR1 = {'TEMP'};
STR2 = {'200'};
STR3 = {'.DAT'};
filename1 = strcat(STR1,STR2,STR3);
filename2 = 'TEMP200.DAT';
%load filename;
A = importdata(filename2);
B = importdata(filename1);
Output is here
??? Error using ==> importdata at 123
Unable to open file.
Error in ==> Averaging at 16
B = importdata(filename2);
String comparison gives '1'
TF = strcmp(filename1,filename2)
TF =
1
Any idea what is going wrong.
Thank you
0 件のコメント
回答 (2 件)
Image Analyst
2012 年 12 月 11 日
編集済み: Image Analyst
2012 年 12 月 11 日
I wouldn't even mess with cell arrays, but if you really want to, use sprintf() and char():
STR1 = {'TEMP'};
STR2 = {'200'};
STR3 = {'.DAT'};
filename1 = sprintf('%s%s%s', char(STR1), char(STR2), char(STR3))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!