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

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 1 Mai 2014
Modifié(e) : Geoff Hayes le 1 Mai 2014
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by