Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Matrix dimensions must agree error
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Guillaume
2020 年 2 月 19 日
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 件のコメント
Guillaume
2020 年 2 月 19 日
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.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!