Code Error - Matrix dimensions must agree
이전 댓글 표시
There is an error in the code that I can't seem to correct.
Code:
for i = 1:26
T(i,1)=T0;
k1(i,1)=A1*exp(-E1/(R*T(i,1))); --> ERROR "Subscripted assignment dimension mismatch."
end
I tried adding decimals and that didn't seem to work. After the first time through the loop, i and T are both 1x1 in size.
채택된 답변
추가 답변 (1개)
Image Analyst
2012년 5월 5일
If A1, E1, or R are matrices, they must be the same length as each other. The size of T does not matter since you are just using one element of it, which is a scalar. Are any of A1, E1, or R two-D arrays? I hope not but why do you have a second dimension of 1? So, assuming they're all scalars or same-length vectors, you must use .* and not *, and ./ instead of /.
k1(i,1) = A1 .* exp(-E1 ./ (R .* T0))
If they're not arrays, it will still work. Note, I also replaced T(i,1) by T0 since they are the same, according to the way you wrote your code.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!