Filter löschen
Filter löschen

How can I select a part of a matrix ?

5 Ansichten (letzte 30 Tage)
재훈
재훈 am 24 Nov. 2022
Kommentiert: Image Analyst am 24 Nov. 2022
I want to select the component of this matrix, whose first column value is bigger than 4, and the second column value is smaller than 0.6
B =
1.0000 0.3000
2.0000 0.6000
3.0000 0.5000
4.0000 0.7000
5.0000 0.2000
6.0000 0.5000
7.0000 0.4000
8.0000 0.5000
The code below is mine, but it never works,:( please help me.
Chosen_data=[];
for i=1:8;
Chosen_data=B((B(i,1)>4)&(B(i,2)<0.6));
end

Akzeptierte Antwort

Voss
Voss am 24 Nov. 2022
Bearbeitet: Voss am 24 Nov. 2022
B = [1 0.3
2 0.6
3 0.5
4 0.7
5 0.2
6 0.5
7 0.4
8 0.5];
idx = B(:,1) > 4 & B(:,2) < 0.6;
Chosen_data = B(idx,:)
Chosen_data = 4×2
5.0000 0.2000 6.0000 0.5000 7.0000 0.4000 8.0000 0.5000
  2 Kommentare
재훈
재훈 am 24 Nov. 2022
Thank you ;)
Image Analyst
Image Analyst am 24 Nov. 2022
@재훈 If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by