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!