Filter löschen
Filter löschen

Improving a search algorithm

1 Ansicht (letzte 30 Tage)
Natialol
Natialol am 26 Mär. 2013
Hello,
I would like suggestions on how to make the search below more efficient. I concatenate in another script to obtain numeric strings eg 0120001410. I then use the search function below to search for 0110001110 in row 1 obtain the corresponding value in row 2. Can I use logical indexing for this, if so, how.
function y= binge(x)
binge= [00000001, 00000010, 00000020, 00000021, .........,90000000;
0.11111, 2.4433, ..................................,7.2];
i=1;
length=size(binge,2);
while i<=length
if abs(x-binge(1,i))<10e-5
y=binge(2,i);
break;
end
i=i+1;
end
if (i>length)
error('wrong');
end
end
Thanks MN

Akzeptierte Antwort

PT
PT am 26 Mär. 2013
function y = binge(x)
binge= [00000001, 00000010, 00000020, 00000021, .........,90000000;
0.11111, 2.4433, ..................................,7.2];
y = binge(2,binge(1,:) == x);
%or to use the same tolerance as you specified,
% y = binge(2,abs(x - binge(1,:)) < 1e-5);
  2 Kommentare
Natialol
Natialol am 29 Mär. 2013
Thanks PT, can I further improve the search?? The fitness function of which this search is a sub component still takes a very very long time.
Thanks
PT
PT am 1 Apr. 2013
If your table is sorted, you can use a more advanced algorithm. Have you Profiled the run?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by