How to extract data from a 3D Array?
7 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Harald
2024 年 4 月 18 日
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.
回答 (1 件)
Dyuman Joshi
2024 年 4 月 18 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!