I have a piece of code like so:
cond = ~(El.brute(:,:, iTraj) >= El_tmp);
for k = 1:d_unc
jS.brute(k, cond, iTraj) = j(k)+1;
where k and iTraj are integers (stored as doubles in typical Matlab fashion), and cond is a 10 by 3 logical matrix. jS.brute is 5 by 3 by 10 by 250.
The assignment in the 3rd line doesn't do what I expected. If I evaluate
It does not evaluate to j(k)+1 for the places where cond is true. Also, this assignment makes the 2nd size of jS.brute have 30 length.
It seems that Matlab will linearize any logical matrix you give for logical indexing, and it will apply only to one index.
My question is: what is the "best" way to do what I want to do here?
Do I have to use re-shape or is there a better way?
I guess I could permute so that the logical indexes are at the end. Is that better?