Problem with importdata with filename obtained two different ways
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Image Analyst
el 11 de Dic. de 2012
Editada: Image Analyst
el 11 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!