how i can vectorize this code using bsxfun or meshgrid?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to vectorize this code, but I dont know how to start it, I read the help files for both bsxfun and meshgrid but no luck. Can someone please guide how to look at this rather than giving the code. My code is working for me but i want to improve it.
s1= 50;
s2=100;
E_=zeros(s2,s2);
grid_=linspace(-2.5,2.5,s2);
tau=linspace(-pi,pi,s1);
x=cos(tau);
y=sin(tau);
cur=myfun(x,y); %returns vector
for k=1:s2
for m=1:s2
for n=1:s1
R= abs(sqrt((grid_(m)-x(n))^2+(grid_(k)-y(n))^2));
u_(n)= besselj(0,R)*cur(n);
end
E_(k,m)=abs(trapz(tau,u_));
end
end
Thanks
Turker
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!