Hi everyone, I know similar questions have been asked before but I can't find anything that would be relevant for my particular situation. I need to write a function that would retrieve a vector from a matrix of unknown size, operate on it, and then return the results into an output matrix of size equal to the starting matrix. Here is an example of what I need:
start_matrix = rand(5,6,7,8,1000);s = size(start_matrix);output_matrix = zeros(s);for a = 1:s(1) for b = 1:s(2) for c = 1:s(3) for d = 1:s(4) operate_data = start_matrix(a,b,c,d,:); % retrieving the vector of length=1000
outputmatrix(a,b,c,d,:) = fft(operate_data); % using fast fourier transform as an example, there are a few more calculations here
end end endend
Now the number of dimensions can vary and the size of them can vary too, meaning that the number of loops needed will be variable. So my question is, how do I make this work with e.g. size = [10,15,20,500], where I loop through the first three dimensions, doing calculations on vectors of length = 500?
I've been trying to implement something like in this example by Jan:
But I don't know how to make it work when I am not operating on each element, but rather a vector, each time.
Help is greatly appreciated! Thanks.
Best Answer