Replacing elements in Array
4 views (last 30 days)
I have two 48 x 61 matrices, LE and Q. If the first and last row value of LE are the same, for those rows, I want the values of Q to equal Q(:, 61).
This is what I initially wrote, but am getting an error message.
C = find(LE(:,1) == LE(:,61)); % Outputs rows in which first and last values are equivalent.
Q(C,:) = Q(C, 61); % For all values in rows C, make every value in that row (of Q) the last value in row Q.
Error: subscript assignment dimension mismatch.
Any suggestions? Thanks!
More Answers (1)
Albert Yam on 20 Jul 2012
When length(C) > 1 , Matlab doesn't know how to replace the values.
(length(C) x 61) matrix , and a length(C) vector
If you loop it for every C, it should work, someone else might be able to point out a way without looping.
C = find(LE(:,1) == LE(:,61));
Q(C(ii),:) = Q(C(ii), 61);