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

 Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 1 Mai 2014
Bearbeitet: Geoff Hayes am 1 Mai 2014

0 Stimmen

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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by