Extract 3D cells with nonzero elements, from a 3D cell array.
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
George Papas
am 12 Sep. 2016
Kommentiert: George Papas
am 12 Sep. 2016
Hi guys! I have binary masks saved in 3D arrays (e.g. Mask(:,:,40), see attached Matlab file) and I want to extract only the 3D cell arrays which contain nonzero elements in a sequential order (e.g. if these are 20, then NMask(:,:,20)). Any ideas would be much appreciated.
1 Kommentar
Akzeptierte Antwort
KSSV
am 12 Sep. 2016
clc; clear all ;
load Mask.mat ;
k = Combinedmask ;
[m,n,p] = size(k) ;
count = 0 ;
for i = 1:p
ki = k(:,:,i) ;
if sum(any(ki))~=0
count = count+1 ;
iwant{count} = ki ;
end
end
3 Kommentare
Weitere Antworten (1)
Guillaume
am 12 Sep. 2016
Well, if you want nice and concise:
filteredmask = Combinedmask(:, :, any(any(Combinedmask, 1), 2))
No need for cell arrays, loops, ifs, etc., just one line.
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!