I am trying to divide and getting the error message "matrix dimensions must agree". What does this mean?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Stephen23
am 23 Okt. 2017
Bearbeitet: Stephen23
am 23 Okt. 2017
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 Kommentar
Stephen23
am 23 Okt. 2017
Bearbeitet: Stephen23
am 23 Okt. 2017
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.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!