How can I select a part of a matrix ?

4 vues (au cours des 30 derniers jours)
재훈
재훈 le 24 Nov 2022
Commenté : Image Analyst le 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

Réponse acceptée

Voss
Voss le 24 Nov 2022
Modifié(e) : Voss le 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 commentaires
재훈
재훈 le 24 Nov 2022
Thank you ;)
Image Analyst
Image Analyst le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by