Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
'Matrix dimensions must agree'
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Star Strider
el 11 de Feb. de 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.
Respuestas (1)
Jan
el 12 de Feb. de 2017
Editada: Jan
el 12 de Feb. de 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 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!