for looop convert to arrayfun
7 views (last 30 days)
Show older comments
I want to convert these for loops into an arrayfun. Always give me an error
"All of the input arguments must be of the same size and shape.
Previous inputs had size 31 in dimension 1. Input #5 has size 1"
[X,Y,Z] = sph2cart(ThetaRad,PhiRad,1.0);
nElec = length(M.lab);
EF(nElec,nElec) = 0;
for i = 1:nElec;
for j = 1:nElec;
EF(i,j) = 1 - ( ( (X(i) - X(j))^2 + ...
(Y(i) - Y(j))^2 + (Z(i) - Z(j))^2 ) / 2 );
end;
end;
I tried to create a new funciton:
function EF = gpuefg(X,Y,Z, maxiter)
EF(maxiter,maxiter) = 0;
for i = 1:maxiter;
for j = 1:maxiter;
EF(i,j) = 1 - ( ( (X(i) - X(j))^2 + ...
(Y(i) - Y(j))^2 + (Z(i) - Z(j))^2 ) / 2 );
end;
end;
end
And call it
EFG = gpuArray(EF);
.
.
.
EFG = arrayfun(@gpuefg,X,Y,Z, nElec, 'UniformOutput', false );
But not working, how should I do this?
2 Comments
David Hill
on 29 Apr 2021
Please explain what you are trying to do. What are your inputs and expected outputs?
Accepted Answer
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!