How to call vector in matrix with condition?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by