Why 'for loop' is very slow even working on server

조회 수: 2 (최근 30일)
Shakir Hussain
Shakir Hussain 2018년 10월 20일
댓글: Shakir Hussain 2018년 10월 26일
My 'for loop' looks like
iwant = cell(a,b);
for i =1:17
c = data(:,:,i);
for j = 1:b
idx = inpolygon(X(:),Y(:),S(j).X , S(j).Y);
iwant{i,j} = c(idx);
end
end
Where a =17,c = 420*940, X = 420*940, Y = 420*940 and b = 1*1 which is polygon and its size is (shape_area 56.4087, x= 1*679340, y = 1*679340).
This for loop is taking very long time even days, so how could I execute it in minimum time
Thank you in advance for any kind of help

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 20일
The idx results are the same for all i values for a given j. Loop over j precomputing them and then loop over i pulling out the appropriate entries.
  댓글 수: 9
Walter Roberson
Walter Roberson 2018년 10월 23일
I do not know what the individual entries in your cell array are intended to mean.
Shakir Hussain
Shakir Hussain 2018년 10월 25일
The test data has attached here, which I want to convert into a matrix having 17 rows and columns according to data size. I was facing problem to attached sample data here from last few days

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

추가 답변 (1개)

Bruno Luong
Bruno Luong 2018년 10월 20일

As I mention in another thread you can get on FEX that can be 100 times faster than MATLAB inpolygon, let alone the newy polyshape

  댓글 수: 7
Walter Roberson
Walter Roberson 2018년 10월 25일
tt = cell2mat(cellfun(@transpose,test,'uniform',0));
Shakir Hussain
Shakir Hussain 2018년 10월 26일
Thank you so much sir Walter

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

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by