How can I speed up an exponential function?
显示 更早的评论
I am trying to get the (element-wise) exponential of a Matrix but I don't need most of the results. How can I use this to optimize my code. My attempts:
% Speedtest exponential
m=1000;
n=2000;
test1=rand(m,n);
tic
result=10.^test1;
toc
tic
test1(test1>0.01)=1;
result=10.^test1;
toc
tic
result=zeros(m,n);
for it1=1:m
for it2=1:n
if test1(it1,it2) > 0.01
result(it1,it2)=10^test1(it1,it2);
end
end
end
toc
I'm getting the following results:
Elapsed time is 0.095385 seconds.
Elapsed time is 0.021221 seconds.
Elapsed time is 0.167990 seconds.
Any way to do this more efficiently?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!