How to call vector in matrix with condition?

1 回表示 (過去 30 日間)
ha ha
ha ha 2017 年 11 月 21 日
編集済み: ha ha 2017 年 11 月 22 日
Hello, I have: n-by-4 matrix A:
A=[ x1 y1 z1 5 % x1,y1,z1: coordinate of point 1
x2 y2 z2 5 % x2,y2,z2: coordinate of point 2
x3 y3 z3 9 % x3,y3,z3: coordinate of point 3
x4 y4 z4 1 % x4,y4,z4: coordinate of point 4
x5 y5 z5 1 % x5,y5,z5: coordinate of point 5
x6 y6 z6 1] % x6,y6,z6: coordinate of point 6
Question: How can i call x,y,z from value of column 4?
Example: I wanna call only row contaning the value "[9 ;5]" in column 4?
result=[x3 y3 z3
x1 y1 z1
x2 y2 z2]
or I wanna call only row contaning the value "[1; 9 ;5]" in column 4?
result=[x4 y4 z4
x5 y5 z5
x6 y6 z6
x3 y3 z3
x1 y1 z1
x2 y2 z2]

採用された回答

M
M 2017 年 11 月 21 日
Maybe something like this :
m=[1 2 3 10;4 5 6 15;7 8 9 20]
m=
1 2 3 10
4 5 6 15
7 8 9 20
result=m(ismember(m(:,size(m,2)),[15;20]),1:end-1)
result =
4 5 6
7 8 9
or a second example :
m=[1 2 3 4 5 50;7 8 9 10 11 50;12 13 14 15 16 60]
m =
1 2 3 4 5 50
7 8 9 10 11 50
12 13 14 15 16 60
result=m(ismember(m(:,size(m,2)),50),1:end-1)
result =
1 2 3 4 5
7 8 9 10 11

その他の回答 (1 件)

Star Strider
Star Strider 2017 年 11 月 21 日
Try this example:
A = [randi(9, 6, 3) [5 5 9 1 1 1]'];
Idx1 = any(A(:,4) == [9 5], 2);
B1 = A(Idx1, 1:3);
Idx2 = any(A(:,4) == [9 5 1], 2);
B2 = A(Idx2, 1:3);

カテゴリ

Help Center および File Exchange3-D Scene Control についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by