I am trying to divide and getting the error message "matrix dimensions must agree". What does this mean?
4 次查看(过去 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!