Remove elements in Matrix

I plotted Position vs Time data. The user is then able to click and select points that are bad(noise). No problem so far. What is the best way to remove the selected points from the Position and Time matrices? I have a list of the indices for the points being removed.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 12일

0 개 추천

Position(TheIndices) = [];
Time(TheIndices) = [];

댓글 수: 4

Daniel
Daniel 2011년 10월 12일
I am then left with two vectors... Time and Position. How do I reshape them back to matrices?
Walter Roberson
Walter Roberson 2011년 10월 12일
What are their original shapes? And are you wanting to remove individual points here and there or whole rows or whole columns?
If you want to remove individual points here and there but not whole rows or columns, then you could potentially end up with a prime number of remaining elements, which could not be reshaped in to anything other than a vector.
Removing individual points from a matrix or array is usually more trouble than it is worth. Removing rows or columns is easy.
If you do want to remove an entire row or column, you would use (e.g.)
Position(TheIndices,:) = [];
or
Position(:,TheIndices) = [];
Daniel
Daniel 2011년 10월 13일
"Removing individual points from a matrix or array is usually more trouble than it is worth."
I am interested in removing individual points from a matrix.
I have no problem finding, selecting and removing the points... but I can't remove the points and maintain the shape of the matrix. I was I could delete a value and shift the column up... like in Excel! Just fill the missing value at the end with a zero or something.
My best solution so far is to replace the bad value with NaN. Matlab will not plot NaN... resulting in a gap in the graph. I can omit them when processing the data later in the program.
Any other ideas?
Walter Roberson
Walter Roberson 2011년 10월 18일
if ~isempty(TheIndices)
sz = size(Position);
Position(TheIndices) = [];
Time(TheIndices) = [];
Position(prod(sz)) = 0; %0 fill
Time(prod(sz)) = 0; %0 fill
Position = reshape(Position,sz);
Time = reshape(Time,sz);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by