"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!