Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
'Matrix dimensions must agree'
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Star Strider
le 11 Fév 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.
Réponses (1)
Jan
le 12 Fév 2017
Modifié(e) : Jan
le 12 Fév 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
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!