How to call vector in matrix with condition?
Show older comments
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
More Answers (1)
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 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!