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.

 采纳的回答

Hi,
and what about A1, E1, R? Are they 1x1 as well or is one of them a vecotr/matrix?
Titus

更多回答(1 个)

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!

Translated by