for looop convert to arrayfun
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
David Hill
2021-4-29
Please explain what you are trying to do. What are your inputs and expected outputs?
采纳的回答
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!