Arrayfun with multidimensional input
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kishore Rajendran
am 8 Feb. 2017
Kommentiert: Kishore Rajendran
am 9 Feb. 2017
I have a function that take three inputs. The first two inputs (say 'a' and 'b') are integers, and the third input (M) is a 3D matrix. The function performs some computations on M using the integer inputs a and b (eg. dataOut = a + b .* (M)). Now let's say we have several values for a and b, stored as vectors while M is constant. I want to vectorize my function using arrayfun, but arrayfun requires the inputs (a,b,M) to be of the same size. I tried passing M as a structure that matches the size of a and b, but that doesn't work either. Eventually, if arrayfun works for this case, I would store a, b and M as gpuArrays and would like to run the code on GPU. Any help is appreciated.
2 Kommentare
James Tursa
am 9 Feb. 2017
If "a" and "b" are vectors, what would the desired output be? A 4D array?
Akzeptierte Antwort
Edric Ellis
am 9 Feb. 2017
a = 1:10;
b = rand(1, 10);
M = rand(4);
arrayfun(@(aa, bb) norm(aa + bb.*M), a, b)
This sort of approach can work for gpuArray too, but beware that the functions that you are allowed to call inside gpuArray arrayfun is restricted to this list.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu GPU Computing in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!