Hi,
Let A be a 1-D array. Let k be a 1-D array of the same length as A, containing the moving mean window length for each corresponding element of A. The following code gives you the moving mean with nonuniform window lengths without using a loop for computation. The loop only creates the function handle.
functionHandleString = "movmeanNonUniform = @(A,k) diag([movmean(A,k(1))";
for i = 2:length(k)
functionHandleString = functionHandleString + "; movmean(A,k(" + num2str(i) + "))";
end
functionHandleString = functionHandleString + "]);";
eval(functionHandleString);
movmeanNonUniform (A,k)