I have a three dimensional matrix (A) and I want to remove rows that contain 0. I tried to do this in a 'for loop', but it gives an error "A null assignment can have only one non-colon index.". When I replace [] with NaN, it seems the code and index are right. Does it possible to do this outside of 'for loop'? Thank you in advance for your help.
clear allclcA1 = [50, 1, 130; 50, 1, 140; 0, 0, 0; 0, 0, 0];A2 = [0, 0, 0; 51, 2, 131; 51, 2, 141; 0, 0, 0];A3 = [0, 0, 0; 0, 0, 0; 52, 3, 132; 52, 3, 142];A (:,:,1)= A1;A (:,:,2) = A2;A (:,:,3) = A3;disp (A)[r,c] = size(A);for i = 1:3 for h = 1:r if A (h,:,i) == 0 A (h,:,i) = [] ; % = NaN
end endenddisp(A)
Best Answer