how can i use max funtion in arrayfun on GPU
Show older comments
The following code makes an error.
Error using gpuArray/max. Too few arguments into max... blabla..
In Matlab manual, max function is supported in arrayfun. What should I do for this error?
If I remove the case of max, the code is valid. But as you can see, in case of max, even though b2 has no 100, the code makes an error.
function a = test_gpu6()
aa = rand(1000, 50, 'gpuArray');
b1 = gpuArray.colon(1, 1000)';
b2 = gpuArray([1 1 2 3 1]);
bb = arrayfun(@gpu_sin, b1, b2);
function a = gpu_sin(i, j)
if j == 1
a = sin(aa(i, 1));
elseif j == 2
a = cos(aa(i, 1));
elseif j == 3
a = tan(aa(i, 1));
elseif j == 100
a = max(aa(:, j));
end
end
end
I don't expect that "just use max(aa)" or something like that. Because this kind of programming is a kind of system.
I am looking forward to your brilliant answer. Thank you very much.
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with GPU Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!