how to solve "Subscripted assignment dimension mismatch" error?
Show older comments
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 Comments
Jan
on 29 Nov 2011
Are there empty lines between the lines in your file?
Walter Roberson
on 29 Nov 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
on 29 Nov 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...
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!