Matrix dimensions must agree error

조회 수: 1 (최근 30일)
Ryan DiTullio
Ryan DiTullio 2019년 11월 19일
답변: Walter Roberson 2019년 11월 22일
I am trying to graph P as a function of the 4 variables listed, but before I can even get to the graph I keep getting the error message Matrix dimensions must agree:
t=[1:1:5];
V=[1000:1:2500];
D=[2:1:5];
A=[1:1:6];
P=(1+(1./t)).*V.*((D./2)+A);
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 11월 19일
No two of your variables are the same size. What size are you expecting the output to be? 5 x 1501 x 4 x 6 ?

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

답변 (2개)

Urmila Rajpurohith
Urmila Rajpurohith 2019년 11월 22일
Addition and element wise multiplication is possible only with matrices of same dimensions.
Try to make sure your matrices are of required sizes by padding them with either 0's or 1's if possible.

Walter Roberson
Walter Roberson 2019년 11월 22일
t=[1:1:5];
V=[1000:1:2500];
D=[2:1:5];
A=[1:1:6];
[tg, Vg, Dg, Ag] = ndgrid(t, V, D, A);
P = (1+(1./tg)).*Vg.*((Dg./2)+Ag);
The result will be a 4D array, 5 x 1501 x 4 x 6 . You will have a fair bit of difficulty plotting the result, as it requires 5 dimensions to represent (four independent dimensions and one dependent dimension.)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by