Why am I getting an 'Unable to open file.' error with importdata?
Show older comments
Hi,
Patience is requested for the simple question, I haven't used Matlab since undergrad times.
I need to understand how to avoid an error with 'importdata'. Using 'importdata' or 'csvread' I get 'Unable to open file' errors, even when I can see the file being read if I caption 'importdata' with 'eval'.
I tested it with debugger and the filename is resolving correctly. When I use the filename as a string, it works ok. When I use uiimport it works also. Obviously these solutions won't be practical for many repetitions (numreps is in the order of 100s).
Looking at the variable workspace I can see that 'newfile' is actually populated with the correct data.
I am running MATLAB R2011b on OSX 10.8.
for n = 0:numreps
fle = strcat('batchRun', num2str(n,'%03d'), '_crt.csv');
%newfile = importdata(fle);
%newfile = importdata('batchRun000_crt.csv')
eval('newfile = importdata(fle)');
end;
Thanks in Advance,
4 Comments
Walter Roberson
on 7 Nov 2012
Are you sure you want %04s and not %04d ?
Angus
on 7 Nov 2012
"eval('newfile = importdata(fle)');"?! Why not:
newfile = importdata(fle);
I'd prefer SPRINTF, but this might be a question of taste:
fle = sprintf('batchRun%03d_crt.cvs', n);
Angus
on 8 Nov 2012
Accepted Answer
More Answers (1)
Angus
on 7 Nov 2012
0 votes
Categories
Find more on Standard File Formats in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!