how to solve "Subscripted assignment dimension mismatch" error?
Mostrar comentarios más antiguos
Hi everyone, any help on this will be highly appreciated!!
Here is my program:
fid = fopen('test.cal');
[paramlist l] = textscan(fid, '%s %s %s %s %s'); %paramlist is a variable
fclose(fid);
[len wid] = size(paramlist{1}); %len=3, wid=4
chanlist = zeros(3,4); %chanlist is a variable
chanlist(1,1:4) = [paramlist{2}{1},paramlist{3}{1},paramlist{4}{1},paramlist{5}{1}]; %write the info from the test.cal into the 1st row of matrix, chanlist. Error happen due to this line.
Here is the "test.cal" file:
channel DIGOUT 0 0 shutter1
channel DIGOUT 0 1 shutter2
channel DIGOUT 0 2 shutter3
When I run the program, the error "subscripted assignment dimension mismatch" will show up, I really dont know how resolve it.
3 comentarios
Jan
el 29 de Nov. de 2011
Are there empty lines between the lines in your file?
Walter Roberson
el 29 de Nov. de 2011
It turns out not to matter if there are blank lines if you are using %s format: %s skips leading whitespace (just like the number formats do), so textscan() would skip over the blank lines.
Jan
el 29 de Nov. de 2011
@Walter: Correct. I just wanted to be sure, that we are talking about the same problem.
@Yu Wang: The problem gets obvious, if you try to run your program line by line. Most of all running "[paramlist{2}{1},paramlist{3}{1},paramlist{4}{1},paramlist{5}{1}]" in the command window reveals the error.
It is a good idea to perform some debugging, when a problem occurs...
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!