Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

'Matrix dimensions must agree'

1 visualizzazione (ultimi 30 giorni)
Alexandra Ridgway
Alexandra Ridgway il 11 Feb 2017
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hi, can someone please advise as to how to fix this error. Ive tried just using * or using dz(j) in the final68 sum (though I think the latter would have given me the wrong answer anyway) but its not fixing it. Fe68 is iron data form a model. I can contour a hydrothermal plume by plotting Fe68 against depth and longitude however below I am trying to quantify the plume into number in m^2 (dlong is longitude converted into meters).
dlong = 109079.92
anom68(find(Fe68<=0))=0
anom68(find(Fe>0))=1
for j=2:31
dz(j)=abs(depth(j)-depth(j-1))
end
final68 = anom68.*dz(:).*dlong
sum(final68)
Thank you.
The error message just states 'matrix dimensions must agree', 'error in line 101 (final68 = anom68.*dz(:).*dlong)'.
Alexandra
  3 Commenti
Star Strider
Star Strider il 11 Feb 2017
Please provide more information, specifically the size results of the arrays used in your calculations. The row and column sizes of the matrices in you calculations must be the same.
Alexandra Ridgway
Alexandra Ridgway il 11 Feb 2017
Hi Star, dlong is just one number while dz is 1x31. anomFe68 is 1x4429. Thanks for your help :) Alexandra

Risposte (1)

Jan
Jan il 12 Feb 2017
Modificato: Jan il 12 Feb 2017
The error message means, that the number of elements of anom68 and dz differ, or at least they do not have the same size. Try this:
dbstop if error
Then run your code again until Matlab stops. Then type in the command window:
size(anom68)
size(dz(:))
If the sizes do not match, the elementwise multiplication .* is not possible. Based on provided information, a suggestion for improvement is not possible.
Note: Although runtime does not matter here, consider the MLint message, which appears in the editor: omit the find() command, which is not required but wastes time only:
anom68(Fe68<=0) = 0
anom68(Fe>0) = 1

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by