MATLAB Answers


How to fix "Subscripted assignment dimension mismatch," in a for loop?

Alec Carruthers さんによって質問されました 2018 年 4 月 11 日
最新アクティビティ Alec Carruthers さんによって コメントされました 2018 年 4 月 11 日
for k=1:length(index)
syms w
W_TO(k) = vpasolve(((C1(k)+C5(k))*(w^1.195))+(C2*(w^.235))+((C3+C4(k)+C6(k)+C7+C10-1)*w)+(C8+C9)==0,w);
The error message I get it is: "Subscripted assignment dimension mismatch.
Error in sym/privsubsasgn (line 1107) L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 944) C = privsubsasgn(L,R,inds{:});
Error in Weight (line 250) W_TO(k) = vpasolve(((C1(k)+C5(k))*(w^1.195))+(C2*(w^.235))+((C3+C4(k)+C6(k)+C7+C10-1)*w)+(C8+C9)==0,w);"
For each k value, I should be getting one value for W_TO. My guess is that there is no analytical solution to this expression. I would appreciate the advice anyone can give on fixing this issue.

  0 件のコメント

サインイン to comment.

1 件の回答

Star Strider
回答者: Star Strider
2018 年 4 月 11 日

I cannot run your code because I do not have the constants.
Your guess may be correct. However saving ‘W_TO’ as a cell array instead may at least prevent the error your code is currently throwing:
W_TO{k} = vpasolve(((C1(k)+C5(k))*(w^1.195))+(C2*(w^.235))+((C3+C4(k)+C6(k)+C7+C10-1)*w)+(C8+C9)==0,w);
You can sort out any multiple results for each ‘k’ iteration after the loop completes.

  3 件のコメント

Alec Carruthers 2018 年 4 月 11 日
You are right about using a cell array for "W_TO" because that fixed the issue. However, now I get three outputs of "[]"? Im not sure what that means.
Walter Roberson
2018 年 4 月 11 日
MATLAB was not able to find numeric solutions for those three cases. Possibly they do not exist, or possibly it is just too hard for MATLAB.
Alec Carruthers 2018 年 4 月 11 日
Alright, that is what I was thinking.
Thank You!

サインイン to comment.

Translated by