How to call vector in matrix with condition?

1 view (last 30 days)
ha ha
ha ha on 21 Nov 2017
Edited: ha ha on 22 Nov 2017
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]

Accepted Answer

M
M on 21 Nov 2017
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

More Answers (1)

Star Strider
Star Strider on 21 Nov 2017
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);

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!