필터 지우기
필터 지우기

What is the faster mean to find a value of an array?

조회 수: 1 (최근 30일)
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014년 5월 5일
댓글: Image Analyst 2014년 5월 7일
Hi all,
I am looking for the fastest search inside an array. For example A3 array has 6250 elements:
[i,j] = find(A3(:,1) == Total);
Total = A3(i,j+1);
This method takes about a minutes to decide if the value "Total" is in the array A3 or not! which is long time :(
Is there any solution for the problem?
Thanks : )

채택된 답변

Image Analyst
Image Analyst 2014년 5월 5일
Get a faster computer. Look at my results:
% Create sample array of 6250 elements
A3 = [randi(9, [1250,4]), ones(1250,1)];
numberOfElements = numel(A3)
Total = 8;
tic;
[i,j] = find(A3(:,1) == Total);
Total = A3(i,j+1);
toc
Elapsed time is 0.000033 seconds.
Is that 33 microseconds I'm getting? And you're getting minute(s)? Something doesn't add up.
  댓글 수: 12
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014년 5월 7일
편집: Abdulatif Alabdulatif 2014년 5월 7일
perfect!!
when I removed sym(), it works like a tick! : )
I am wondering if there is any interpret for why this is happen?!
Thanks for all : )
Image Analyst
Image Analyst 2014년 5월 7일
I have no ideas about SYM since I don't have that toolbox. Can you mark my Answer as "Accepted" now? Thanks.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by