Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
index exceed matrix dimesion error, earlier GUI was running all fine, all sudden it comes like this
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Guillaume
el 18 de Jun. de 2015
Editada: Guillaume
el 18 de Jun. de 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))
Respuestas (1)
Guillaume
el 18 de Jun. de 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 comentarios
La pregunta está cerrada.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!