Debugging Help - Write a series of filenames

I'm writing a series of filenames to an array but am having issues with size mismatching.
q=[1:1000];
for n=1:1000
myfile(n)=sprintf('data_%06d.dat',q(n))
end

 Accepted Answer

Hi Cameron,
If I try to run the same code, I get the "Subscripted assignment dimension mismatch.". The problem is in the assignment to myfile. The return of the sprintf (for any N) is a character array of length 15 - so one row and fifteen columns. When assigning this to the myfile matrix, the code requires more than just the row, but the columns for which the sprintf result is destined to:
myfile(n,:)=sprintf('data_%06d.dat',q(n));
Here the colon just means "all columns". Try this and see what happens. (Also consider pre-allocating memory for the myfile matrix.)
Geoff

More Answers (0)

Categories

Tags

Asked:

on 30 Apr 2014

Edited:

on 1 May 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!