How can I select a part of a matrix ?

5 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2022-11-24
编辑:Voss 2022-11-24
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 个评论
Image Analyst
Image Analyst 2022-11-24
@재훈 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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by