delete row in matrix if value in another matrix is unique

조회 수: 1(최근 30일)
Frederik Reese 2022년 7월 19일
답변: Jonas 2022년 7월 19일
Hi,
probably a simple question, but I need your help.
I have 2 matrices with 1 column each. Values ​​appear twice in the first matrix (x1). I select this with unique and delete it. In the 2nd matrix (y1) I want to delete the same row as in matrix 1. So e.g. Row 12 contains twice the value and is deleted, then row 12 in the other matrix should also be deleted after that they should contain the same number of values.
The two matrices are attached
Thank you very much

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

채택된 답변

Jonas 2022년 7월 19일
you want to delete entries when the number is repeated first?
firstVec=[5 3 5 1 7 9 3 1 4];
secVector=1:numel(firstVec)
secVector = 1×9
1 2 3 4 5 6 7 8 9
[~,firstOnly]=unique(firstVec,'stable')
firstOnly = 6×1
1 2 4 5 6 9
% keep only entries at first number occurence
secVector(firstOnly)
ans = 1×6
1 2 4 5 6 9

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

범주

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by