I am assigning a 3D array, which contains some information for a number of different loadcases. Each row in the array defines a particular loadcase (of which there are 3) and I would like to remove the loadcase (i.e. the row) if ALL the elements of the row (in 3D) are equal to zero.
The code I have at the moment is:
Array = zeros(3,5) %# Initialise array
Numloadcases = 3;
Array(:,:,1) = [10 10 10 10 10;
0 0 0 0 0;
0 0 0 0 0;]; %# Expand to a 3D array
Array(:,:,2) = [10 10 10 10 10;
0 0 0 0 0;
0 0 0 0 0;];
Array(:,:,3) = [10 10 10 10 10;
0 0 0 0 0;
0 0 20 0 0;];
Array(:,:,4) = [10 10 10 10 10;
0 0 0 0 0;
0 0 20 0 0;];
%# And to remove the second row:
for i = 1:Numloadcases
if sum(Array(i,:,:)) == 0
Array(i,:,:) = [];
end
end
At the moment, the for loop I have to remove the rows causes an indexing error, as the size of the array changes in the loop.
Can anyone see a work around for this?