Replacing elements in Array

조회 수: 7 (최근 30일)
Angela
Angela 2012년 7월 20일
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!
  댓글 수: 1
Image Analyst
Image Analyst 2012년 7월 20일
It's always nice if the poster supplies some sample data in advance to make it easy for people to try things for her. I mean, why make it hard for people to help you?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 7월 20일
Q(C, :) = repmat(Q(C, 61), 1, size(Q, 2));

추가 답변 (1개)

Albert Yam
Albert Yam 2012년 7월 20일
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));
for ii=1:length(C)
Q(C(ii),:) = Q(C(ii), 61);
end

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by