Error: Inner matrix dimensions must agree.

조회 수: 1 (최근 30일)
Mohammad Sohel Rana
Mohammad Sohel Rana 2017년 4월 20일
편집: Jan 2017년 4월 20일
Size of Fh and Reh is [15 25] and size of Prh is [1 25]
for i=1:1:N1
for j=1:1:length(Dd)
Nuh(:,i)=((Fh(:,i)/8)*(Reh(:,i)-1000)*Prh(i))/(1+12.7*(Fh(:,i)/8).^(0.5).*(Prh(i).^(2/3))-1);
end
end
How I can overcome the error.

채택된 답변

Jan
Jan 2017년 4월 20일
편집: Jan 2017년 4월 20일
We have to guess what you want to achieve, because all we see is the failing code. If you mention the intention (preferrably in a comment, such that you can read it also, when you try to maintain the code in 2 years), suggesting an improvement is more reliable.
Look at this expression:
(Fh(:,i) / 8) * (Reh(:,i) - 1000) * Prh(i))
This is the multiplication of two [15 x 1] vectors, but this is not allowed (in Matlab and mathematically). What is the wanted output? Either use the elementwise multiplication:
(Fh(:,i) / 8) .* (Reh(:,i) - 1000) * Prh(i))
or transpose the 1st vector:
(Fh(:,i).' / 8) * (Reh(:,i) - 1000) * Prh(i))
The division by / will suffer from the same problem. Again either adjust the array dimensions or use the elementwise operation ./ .
You can solve such problems by your own: Split the complicated command into small blocks and process them one by one:
a = Fh(:,i) / 8;
b = (Reh(:,i) - 1000) * Prh(i);
c = sqrt(Fh(:,i) / 8); % SQRT is much faster than ^0.5
... etc
d = a * b;
Nuh(:,i) = (d / (1+12.7*c.*(Prh(i).^(2/3))-1);
Now you can check the dimension of the smaller blocks much easier and find problems efficiently.
Note: Inserting spaces around operators increase the readability.

추가 답변 (0개)

카테고리

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