A = java.util.ArrayList();
A.add(1);
A.add(2);
A.add(3);
A.add(4);
A.add(5);
itr = A.listIterator();
while itr.hasNext()
k = itr.next();
disp(k);
% modify data structure while iterating
itr.remove();
itr.add(k);
end
% This example transposes each field of a struct.
s.a = 1:3;
s.b = zeros(2,3);
s % a: [1 2 3]; b: [2x3 double]
for f = fieldnames(s)'
s.(f{1}) = s.(f{1})';
end
s % a: [3x1 double]; b: [3x2 double]
% Redefining f simplifies the indexing.
for f = fieldnames(s)'
f = f{1};
s.(f) = s.(f)';
end
s % back to a: [1 2 3]; b: [2x3 double]