how can i remove this error in matlab?

2 ビュー (過去 30 日間)
rabia 2012 年 7 月 14 日
for i=1:n-1
c(i,:)=blanks(n*n);
end

サインインしてコメントする。

回答 (2 件)

Sargondjani 2012 年 7 月 14 日
ermm, what error? and what do you actually want the line to achieve? i mean, the code wants to assign a matrix with blanks to column vector...

3 件のコメント

rabia 2012 年 7 月 14 日
the error is "Subscripted assignment dimension mismatch"?
Image Analyst 2012 年 7 月 14 日
Set a breakpoint on that line. In the command window, what does this say
whos c
whos n
Are you absolutely sure c has at least n-1 rows and n*n columns, and are you absolutely sure n is not an array? How did you get c and n in the first place, before you got to the for loop?
rabia 2012 年 7 月 15 日
it gives the ans 1x1 for all c,n and i !

サインインしてコメントする。

Star Strider 2012 年 7 月 14 日
This works fine for me:
n=4;
for k1 = 1:n-1
c(k1,:) = blanks(n*n);
end
Variable ‘c’ is listed as a [3 x 16] character array.
The index ‘i’ may be the problem. Please don't use ‘i’ or ‘j’ for indexing, since MATLAB uses them for its imaginary operators.
If that's not the problem, did you use ‘c’ somewhere earlier in you code as a constant or as vector or as a smaller matrix?

4 件のコメント

Star Strider 2012 年 7 月 15 日
I'm running out of ideas.
You need to know more about what is going on in the loop. Temporarily at least, change your loop to:
for i=1:n-1
c(i,:)=blanks(n*n);
csize = [i size(c)]
end
Leave the semicolon off the end of the ‘csize’ statement so it will display. If ‘n’ isn't too large, this shouldn't be too much of a problem. With luck, you will know when in the loop the error occurs, and something about ‘c’.
Image Analyst 2012 年 7 月 15 日
He said the code worked separately but not in his program. So obviously his program is different than the simplified snippet he shared with us. rabia really needs to learn how to debug using the built in debugger rather than the Answers forum. Debugging with the debugger is so much faster and more efficient than debugging via forum messages. rabia, is there some reason why you're not using the debugger to solve your problem?
Star Strider 2012 年 7 月 15 日
My impression was that he followed your previous suggestion, set a breakpoint, and found that ‘c’ ‘n’, and ‘i’ were all [1x1]. That may have been the first loop iteration. He might have discovered his error (still undetermined) if he had stepped through his loop using the debugger and examined ‘c’ at each iteration. He didn't, so I'm offering an alternative approach such as I used in pre-debugger MATLAB.
My latest suggestion is to provide him with a strategy to see what ‘c’ is doing, since that seems to be the problem, and possibly discover where it's throwing the error. It's easier than explaining the debugger functions.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by