|
Dear Matlab experts!
I have the following problem: 3D subarrays of a 4D array have to multipied by a 3D array and I wonder if this could be achieved more elegantly and efficiently avoiding for loops... (See code below...). Could "arrafun" used for it?
Many thanks in advance,
LS
My soluitons are the following:
Solution 1:
Sample_4D = ones(20,20,20,10000);
Rand_3D= rand(20,20,20);
Results = zeros(size(Sample_4D));
for i =1:size(Sample_4D,4)
Results(:,:,:,i) = Sample_4D(:,:,:,i).*Rand_3D;
end
Solution 2: Transform the 3D into a 4D matrix
Sample_4D = ones(20,20,20,10000);
Rand_3D= rand(20,20,20);
Rand_4D=zeros(size(Sample_4D));
Results = Rand_4D;
for i =1:size(Sample_4D,4)
Rand_4D(:,:,:,i) = Sample_3D;
end
Results = Sample_4D.*Rand_4D;
|