Matrix dimensions must agree error

조회 수: 1 (최근 30일)
Bettie Schelske
Bettie Schelske 2019년 9월 12일
댓글: Image Analyst 2019년 9월 12일
Hi,
To preface, I have no idea what im doing. I am trying to use the equations to get 99 different GammaA's at the 5 different temperatures. However, I understand that the matrix dimensions need to be the same i.e theres way more comp than temp.
I appericate your help.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 9월 12일
Caution:
for i=length(Comp)
would only execute once, with i assigned the length of Comp . You would be more likely to want to use
for i=1:length(Comp)
and you would probably want to use Comp(i) inside the loop.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 9월 12일
Your T is a vector. You have an expression / another expression. The / operator is not ordinary division: it is matrix division, with A/B being similar to A * pinv(B) where * here indicates algebraic matrix multiplication. The numerator you have only has one column, but the denominator has length(T) columns, but the / operator requires that the number of columns be the same.
It is a lot more likely that you would want to use the ./ operator, which is element-by-element division.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 9월 12일
Try 2 for loops:
Comp = 0.01 : 0.01 : 0.99;
T = 400 : 200 : 1400;
R = 8.314;
ohm = 15000;
for k1 = 1 : length(Comp)
for k2 = 1 : length(T)
GammaA(k1, k2) = exp((ohm * (1 - Comp(k1)) ^2) / (R * T(k2)));
end
end
image(GammaA);
% imshow(GammaA, [], 'Colormap', jet(256), 'InitialMagnification', 800,...
% 'XData', T, 'YData', Comp);
ylabel('Comp', 'FontSize', 20);
xlabel('T', 'FontSize', 20);
0000 Screenshot.png
  댓글 수: 2
Bettie Schelske
Bettie Schelske 2019년 9월 12일
편집: Bettie Schelske 2019년 9월 12일
Thank you so much for this! However, I am trying to plot comp vs a (composition vs activity). The GammaA equation is needed to find 99 different a vaules to plot.
Image Analyst
Image Analyst 2019년 9월 12일
Each column of GammaA is 99 values. So there are 5 sets of 99 values. As I'm sure you know, you can extract a column and plot it
for col = 1 : size(GammaA, 2)
plot(Comp, GammaA(:, col), '-');
hold on;
end
This will plot 5 curves of 99 values.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by