필터 지우기
필터 지우기

How to make a for faster?

조회 수: 1 (최근 30일)
Oliver Lestrange
Oliver Lestrange 2020년 8월 29일
편집: Bruno Luong 2020년 8월 29일
Hi,
I've the following code.
ix = ismember(idx_x(:),x(:));
iy = ismember(idx_y(:),y(:));
minimum = min(ix,iy);
for idx_=1:18:length(iy)
for idx=1:18:length(ix)
if minimum(idx)==1
%index =[index;idx];
altura_raio_direto = [altura_raio_direto; heights(idx)];
% saber indices de heights que fazem parte do bresenham
end
iii = iii+1;
disp(iii);
end
end
heights is an array of 90 000 positions, as well as iy and ix.
How can I make this faster?
Thanks!
  댓글 수: 1
Bruno Luong
Bruno Luong 2020년 8월 29일
편집: Bruno Luong 2020년 8월 29일
You must think what is your double-loops are looping on. As long as you still see the need of double-loop you are completely off of understanding ISMEMBER and linear indexing.

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

답변 (2개)

KSSV
KSSV 2020년 8월 29일
idx_=1:18:length(iy) ;
idx=1:18:length(ix) ;
if min(idx)==1
altura_raio_direto = heights(idx) ;
end
altura_raio_direto = repmat(altura_raio_direto,1,length(idx_1)-1) ;
  댓글 수: 1
Oliver Lestrange
Oliver Lestrange 2020년 8월 29일
I am sorry, I forgot to mention what minimum is.
I've already edit the post.
minimum = min(ix,iy);

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


Bruno Luong
Bruno Luong 2020년 8월 29일
편집: Bruno Luong 2020년 8월 29일
ix = ismember(idx_x(:),x(:));
iy = ismember(idx_y(:),y(:));
ixy = ix & iy;
idx = 1:18:size(ixy,1);
altura_raio_direto = heights(idx(ixy(idx)));
%altura_raio_direto = repmat(altura_raio_direto,length(idx,1); % outer loop concatenate the same thing over and over

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by