MATLAB: Loop over an array or list of vectors

arraysloopMATLABSignal Processing Toolboxvectors

Is there a way to loop over an array of signal vectors in Matlab? Python has a way to do it using for loop like:
v1 = [] //signal vector1
v2 = [] //signal vector2
arrv = [v1, v2] //array of signal vectors
for v in arrv:
print len(v)
It would be great if someone can suggest a similar solution if it exists.

Best Answer

While it is possible to loop over array elements directly, in practice it is usually much more convenient and versatile to loop over their indices. You can use a cell array and loop over its indices:
C = {v1, v2}; % cell array
for k = 1:numel(C) % indices
v = C{k};
... do whatever with v
end