MATLAB Answers

How to left divide 4D arrays

6 views (last 30 days)
If I have two 2D gpuArrays f(NxM) and f1(NxM) of same size, then I can left divide them like this:
beta=arrayfun(@(n) f(:,n)\f1(:,n), 1:size(f,2));
What would be the way to do this if both f and f1 are 4D arrays of size (NxMxZxK)?


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jul 2018
beta = arrayfun(@(n) f(:,n)\f1(:,n), 1:numel(f)/size(f,1));
after which you will need to reshape() to the appropriate size.


Mantas Vaitonis
Mantas Vaitonis on 19 Jul 2018
On my machine it takes about 7,5 seconds:
Elapsed time is 7.577014 seconds.
I use other functions with arrayfun, pagefun on same algorithm with same data and it for evey other function it takes less then 0,01 second. One more thing when I use profiler it says there were 4000 calls in der>@(n)f(:,n)\f1(:,n), is in tuppose to pas data in parallel? I have quite a big chunks of data and looking for ways to speed the calculations.
Walter Roberson
Walter Roberson on 19 Jul 2018
The left division of two real-valued column vectors A\B, is equal to the dot product of the two vectors divided by the square of the norm of A (that is, the sum of squares of the elements of A)
Mantas Vaitonis
Mantas Vaitonis on 22 Jul 2018
@Walter Roberso, great thank you, using the method you did suggest speed up is more then 100x times:
aaa = randi([-10 10], 5,4,10,100 );
bbb = randi([-10 10], 5,4,10,100 );
f = gpuArray(aaa );
f1 = gpuArray(bbb );
S = sum(rr,1);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by