I have a scenario in MATLAB where I would like to evaluate a function for certain parameter values. The parameters are extracted from an arbitrary number of arrays, and each array can have an arbitrary number of elements. I know the number of arrays and the number of elements in them before I call the function.
For example, say I have arrays A = [a1 a2 ... aL], B = [b1 b2 ... bM] and C = [c1 c2 ... cN].
for i = 1:length(A)
for j = 1:length(B)
for k = 1:length(C)
myfunc(A(i), B(j), C(k))
end
end
end
I am considering taking the L elements of A, M elements of B and N elements of C, and flatenning them into a cell array, and iterating with a single for loop over this cell array.
I was wondering if there was a MATLAB function that does something like this ... The result does not have to be a cell array. I want a way to avoid having multiple nested for loops. It is fine for a small number of loops, but as this number grows, it is pretty difficult to read and maintain.