I am stuck with this simple matrix operation. I have the 4D matrix called F, class double, with size(F)= 10 345 345 14. (I am not quite sure if I should have converted to logical) It contains 0s and 1s and it represents a mask after some operations to check neighbouring. I need to see for each 'object' (first dimension, 1:10), if there are any non-zero values and create a logical array Con with size(Con)=10 that will have 1 if there are non-zero values, or 0 if all values are 0. I tried many different approaches, I am not sure how many 'any' I should put and if I need to apply squeeze every time. This is my code:
[m,n,o,p]=size(F);
for ob=1:m %for each object
A=F(ob,:,:,:);
A=squeeze(A);
if any(A(:))
Con(ob)=1;
else
Con(ob)=0;
end
end
Any help would be greatly appreciated, thanks!
Ziggy.
Try this -
Con = any(reshape(F,m,[]),2)