help me to reduce my function time runing
2 次查看(过去 30 天)
显示 更早的评论
Hi every body
This is my code
if true
for r = 1:100
U = 1 * (r-1);
for c = 1:100
V = 2 * (c-1);
F(r,c) = 10 * sin(U + V);
end
end
imagesc(F);
colormap(gray);
end
Its generate a replicate pattern which I upload it here. Is there any suggestion to reduce the running time for this code?
Thanks
0 个评论
采纳的回答
Roger Stafford
2014-10-21
U = (0:99).';
V = 0:2:198;
F = (10*sin(U))*cos(V)+(10*cos(U))*sin(V);
imagesc(F);
colormap(gray);
0 个评论
更多回答(1 个)
Henrik
2014-10-21
编辑:Henrik
2014-10-21
This should work:
if true
F=zeros(100,100); %always preallocate
c = 1:100;
V = 2 * (c-1);
for r = 1:100
U = 1 * (r-1);
F(r,:) = 10 * sin(U + V);
end
imagesc(F);
colormap(gray);
end
You can get rid of the r loop too with e.g. bsxfun, but I don't have time to test it right now
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!