Question
I am trying to select two out of 6 points in an array whose size is 6x3xn. These two points are not in the same row on each page as I am trying to select those two of the six points that meet a certain condition. Let's assume that condition is that every coordinate is between 0 and 30. Is there away to do this without loops?
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 23, 2026
n = 2; X = randi(40, 6, 3, n)
X =
X(:,:,1) =
25 18 19
19 23 18
26 5 7
15 39 10
22 35 10
26 35 23
X(:,:,2) =
35 22 6
25 29 2
5 39 5
34 33 36
32 14 17
5 22 33
mask = all(X >= 0 & X <= 30, 2)
mask = 6×1×2 logical array
mask(:,:,1) =
1
1
1
0
0
0
mask(:,:,2) =
0
1
0
0
0
0
Y = reshape(X(cat(2, mask, mask, mask)), [], 3)
Y = 4×3
25 23 7
19 5 25
26 19 29
18 18 2
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related indexing Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →