I am trying to divide and getting the error message "matrix dimensions must agree". What does this mean?
3 ビュー (過去 30 日間)
古いコメントを表示
I have the following piece of code.
for ii = 1:length(k);
for jj = length(trials);
V1 = trials(jj,1) / (1 + ([k,ii] * 0));
V2 = trials(jj,2) / (1 + ([k,ii] * trials(jj,3)));
P2(jj,ii) = 1 / (1 + exp(-B*(V2-V1)));
end
end
When I run the code, I get the following error message.
Error using /
Matrix dimensions must agree.
Error in OptimalStimuliChoiceFINAL (line 31)
V1 = allOptions(jj,1) / (1 + ([k,ii] * 0));
It should be an equation, with figure before the line divisible by the product of the sum after the line, so I am unsure why this error is occurring.
How do I go about fixing this error?
0 件のコメント
回答 (1 件)
Stephen23
2017 年 10 月 23 日
編集済み: Stephen23
2017 年 10 月 23 日
V1 = trials(jj,1) ./ (1 + ([k,ii] * 0));
^ note the dot: mrdivide!
for all of the division operations. It is very important to know the differences between these kind of operations. You can read about them by reading the MATLAB documentation:
1 件のコメント
Stephen23
2017 年 10 月 23 日
編集済み: Stephen23
2017 年 10 月 23 日
Depending on what size B is, your entire RHS is likely non-scalar (i.e. a vector of values). But the indices on the LHS only specify one position (i.e. one value or number). Simply put, you cannot put multiple numbers into the place of one number. That is not how matrices work!
You have not written any code comments, and there is no explanation of what the algorithm should be doing, so I have no idea what you are trying to achieve with that code.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!