필터 지우기
필터 지우기

How to make this loop faster?

조회 수: 3 (최근 30일)
Oliver Lestrange
Oliver Lestrange 2020년 12월 27일
댓글: Jesús Zambrano 2020년 12월 28일
Hello,
The following code takes 30 seconds to execute. I can't make it any faster.
Any suggestion?
Thanks!
function [ at] = obstacleAttenuation( Ant, Movel, Obstaculo,mapa )
tic
fprintf('\nInside obstacleAttenuation function!\n');
at = zeros(mapa.xlength, mapa.ylength);
for xi=1:mapa.xlength
for yi=1:mapa.ylength
att = 0;
[x, y] = bresenham(Ant.Antena_x, Ant.Antena_y, Movel.x(xi), Movel.y(yi));
for i = 1:length(x)
Obs = Obstaculo(x(i), y(i));
att = att + Obs;
end
at(xi, yi) = att;
% Obs = Obstaculo(x(1:length(x)), y(1:length(x)));
% att = sum(sum(Obs));
% at(xi, yi) = att;
end
end
fprintf('\nExit obstacleAttenuation function!\n');
toc
end
NOTE: I am using R2016a version.

답변 (1개)

Jesús Zambrano
Jesús Zambrano 2020년 12월 27일
Is it possible to enter vectors as arguments in the function Obstaculo and get a vector as result? If so, then you could try replacing:
for i = 1:length(x)
Obs = Obstaculo(x(i), y(i));
att = att + Obs;
end
By:
i=1:length(x);
att = sum(Obstaculo(x(i), y(i)));
  댓글 수: 12
Oliver Lestrange
Oliver Lestrange 2020년 12월 28일
Obstaculo has numbers like 14.3, 0, 23... Maybe I should just resize the image...
Thanks for your time!
Jesús Zambrano
Jesús Zambrano 2020년 12월 28일
you're welcome!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by