Code Error - Matrix dimensions must agree
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 5 de Mayo de 2012
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.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!