Hi to all,
I have a 4-D array A of size 81x81x120x120. Each element of this array is an integer with values between 0 and 5.
Now for each element of this array, I need to generate as many random numbers as the value of the element.
For example, if A(1, 1, 1, 1) = 5, I must generate 5 random numbers.
I have tried this approach with the arrayfun:
C = arrayfun(@(x) rand(x, 1), A, 'UniformOutput', false);
where the output is a cell array of the same size as A and each cell contains as many random numbers as the integer value of the corresponding element of A.
Now this approach works, but it's too slow for the purposes of my problem, since I need to run this 500 times.
Is there any way to speed it up?
Thank you very much!