How to extract data from a 3D Array?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a large (500x5x79039) 3D array, which is mostly filled with zeros. Now I want to extract the slices with content into a smaller array and save them. I’ve already tried the solution from this Article, but then I get the same page repeated multiple times, resulting in too many entries and duplicates.
Ideally, I would like to extract the pages exactly as they were saved, provided there is data on those pages.
4 Commenti
Harald
il 18 Apr 2024
Jonas inquired about the direction of indexing. In other words, you can get
a) a n x 5 x 79039 array with n < 500
b) a 500 x n x 79039 array with n < 5
c) a 500 x 5 x n array with n < 79039
Each can be done, but it would be great to know which of the three you are looking for.
Risposte (1)
Dyuman Joshi
il 18 Apr 2024
Use logical indexing -
%Sample data
p = 5;
q = 6;
r = 4;
y = rand(p,q,r)-1;
y(:, :, [2 r+1]) = zeros(p,q,2)
%Check if there is any non-zero element in a page
idx = any(y, [1 2])
%Use the (logical) index to get the corresponding data
out = y(:, :, idx)
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!