Subscripted assignment dimension mismatch.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I really don't understand why I get this error. I'm trying to make a new array that contains the strings from filelist.name so that I can then get rid of the .suffix of my filelist for future manipulations. However, I get the "subscripted assignment dimension mismatch" error when I try to create newfilelist. The error is with the last line of code shown. Up to that point filelist(i).name happily returns the name of the ith file. I'm pretty new to coding so I appreciate any help.
Direc= 'somedirectory';
fileprefix = 'someprefix';
filelist = dir([Direc '/' someprefix '_*']);
newfilelist(1:length(filelist)) = filelist(1:length(filelist)).name;
0 Commenti
Risposte (1)
Guillaume
il 1 Feb 2016
Modificato: Guillaume
il 1 Feb 2016
First, you should use fullfile to build paths rather than building them yourself.
filelist = dir(fullfile(Direc, [someprefix, '_*']));
Secondly, I would use numel instead of length since length behaves very differently with matrices. But in any case, x(1:length(x)) when x is the vector is the same as x, so the whole construct is pointless.
When you ask for a single field of a structure array, matlab returns a comma separated list. If you want to convert that into a single entity, you need to concatenate that list. As the elements of the list are strings, you need to concatenate them into a cell array, thus:
newfilelist = {filelist.name}
0 Commenti
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!