Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
index exceed matrix dimesion error, earlier GUI was running all fine, all sudden it comes like this
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
files=files(3:end,:);
j=1;
for i = 1:size(files,1)
filename = files(i,:);
if exist(['SavedCartridgeSettings\',filename]) ==7
% pattern1 = '.mat';
% pattern2 = '\s{2,}';
% replacement = '';
% filename=regexprep(filename,pattern1,replacement);
% filename=regexprep(filename,pattern2,replacement);
x=strsplit(filename,'-');
mpid(j)=x(1);
name=char(x(2)); % index exceeds matrix dimemsion come here
name=strsplit(name,' ');
mfname(j) =name(1);
mlname(j) =name(2);
j=j+1;
end
end
1 Kommentar
Guillaume
am 18 Jun. 2015
Bearbeitet: Guillaume
am 18 Jun. 2015
I would have thought that files would be a cell array, in which case the line
if exists(['...' , filename]) == 7
would throw an error (as filename would be a cell array which can't be concatenated with a string).
Also, the proper way to convert a cell containing a string into a string is by indexing the cell, not with char:
name = x{2}; %instead of name = char(x(2))
Antworten (1)
Guillaume
am 18 Jun. 2015
Well, you never check that your filename actually contains a '-'. If it does not, then the cell array x will only have one element, so x(2) is not valid.
Most likely, your files comes form a dir command. When dealing with external input (list of files in a folder, user input from a gui), it is always a good idea to check that this input conforms to what you expect. There's no guarantee that the files in the directory all have a '-' in them (maybe somebody mistakenly put another file in there) or that the user only entered numbers, etc.
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!