Problem with importdata with filename obtained two different ways
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Image Analyst
am 11 Dez. 2012
Bearbeitet: Image Analyst
am 11 Dez. 2012
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 Kommentare
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!