Deleting/selecting and subsetting specific slices in a multi-dimensional array
Show older comments
Hello,
I have three variables that are three-dimensional arrays of the size 699 (say, x or rows) x 699 (say, y or columns) x 60 (say, z or slices). I have first computed certain indices using certain conditions. E.g.,
idxs = Z > 5000 & W > 1 & M_tot > 0.05; % Idx is now a logical array of size 699 x 699 x 60.
Now, for further analysis, I am interested in keeping only those slices that satisfy the above conditions. In other words, I want to delete those slices where the idxs at a given x,y are zeros for all z. I used the any function below to create a subset:
subset_idx = any(idxs,3);
This creates a 699 x 699 logical array where I would like to keep all the points corresponding to 1 and delete all the rows and columns corresponding to a 0. This should give me a subset array of size nx, ny, 60 where nx and ny are much less than 699. How do I achieve this?
I tried something like this:
todelete_idx = ~(any(idxs,3)); Size : 699 x 699 logical
idxs(todelete_idx,:) = [];
However, this produces an error since the todelete_idx is a two-dimensional array and I am unable to subset it like this. What is the way around this?
1 Comment
Sai Prasanth
on 29 May 2020
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!