Error: Inner matrix dimensions must agree.

1 次查看(过去 30 天)
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