Error: Inner matrix dimensions must agree.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Sohel Rana
el 20 de Abr. de 2017
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.
0 comentarios
Respuesta aceptada
Jan
el 20 de Abr. de 2017
Editada: Jan
el 20 de Abr. de 2017
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!