Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Matrix dimensions must agree error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Marius Tøndel Eliassen
el 19 de Feb. de 2020
Cerrada: MATLAB Answer Bot
el 20 de Ag. de 2021
I am sure I used this exact code yesterday without problems (line 27)
Matrix dimensions must agree.
Error in abs_threshold_colorationuser (line 27)
m_test(start_idx:end_idx) = m_test(start_idx:end_idx) + 10^(M.VAR/20)*y2;
Error in mpsy_check (line 208)
eval([M.EXPNAME 'user']);
Error in mpsy_afc_main (line 60)
mpsy_check;
Error in abs_threshold_coloration (line 71)
mpsy_afc_main;
Marius
0 comentarios
Respuestas (1)
Guillaume
el 19 de Feb. de 2020
First, do not use eval. It's not the cause for your problem here but it's a very dangerous tool which typically makes it harder to debug your code. It's also completely unneeded here,
M.([EXPNAME, 'user']); %and use , to separate expressions in [], the lack of , is also a typical source of bugs.
would work just as well.
As for the error, we don't have enough information to say what the problem is exactly, most likely the size of m_test(start_idx:end_idx) is not the same as the size of 10^(M.VAR/20)*y2 and the most likely reason for that is that y2 doesn't have end_idx-start_idx+1 elements or if it has, is not a vector. Since we don't know the size of the variables, their shape, or where they come from, we can't help you further.
3 comentarios
Guillaume
el 19 de Feb. de 2020
As I said, the most likely reason is that the length of your vector y2 is not exactly equal to end_idx-start_idx+1. Certainly, the round in the calculation of start_idx and end_idx are suspicious. Are you sure you haven't got an off-by-one error?
You can always add:
assert(numel(y2) == end_idx-start_idx+1, 'Mismatch between length of y2 (%d) and calculated bounds (%d:%d = %d elements)', numel(y2), start_idx, end_idx, end_idx-start_idx+1);
before line 27 which will at least warn you of the problem but of course won't solve it.
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!