"Subscriped assignment dimension missmatch" Error
1 回表示 (過去 30 日間)
古いコメントを表示
So I'm trying to calculate the value of an unknown that would generate the maximum value in a matrix, but I've ran into a problem. I get the error "Subscripted assignment dimension mismatch". So to clarify, I'm looking for the p that, after the operation below is performed, Generates the highest number. I then need to find that p.
pvalues = [0:0.01:1];
v = [1;0];
for i=1:length(pvalues)
p=pvalues(i)
A = [2-p 0.25*p;p (1.25-(0.25*p))];
answer(i) = (A^25)*v;
end
max(answer)
I thought i could work around it, but it seems that it hasn't worked.
0 件のコメント
回答 (1 件)
BhaTTa
2024 年 10 月 21 日
Hey @Lukas Lehrman, hey there is a minor mistake in your code as 'A' is 2x2 matrix and 'v' is 2x1 matrix and the resultant matrix obtained after their multiplication is 2x1 matrix, thereby you should assign the value to answer by doing answer(i,:).
pvalues = [0:0.01:1];
v = [1;0];
for i=1:length(pvalues)
p=pvalues(i)
A = [2-p 0.25*p;p (1.25-(0.25*p))];
answer(i,:) = (A^25)*v;
end
max(answer)
hope it resolved your issue.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!