how to solve "Subscripted assignment dimension mismatch" error?
显示 更早的评论
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 个评论
Jan
2011-11-29
Are there empty lines between the lines in your file?
Walter Roberson
2011-11-29
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
2011-11-29
@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...
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!