How to find particular number in the data vector?

5 ビュー (過去 30 日間)
vimal kumar chawda
vimal kumar chawda 2021 年 6 月 24 日
回答済み: dpb 2021 年 6 月 24 日
clc
clear all
close all
data = randi(100000)
% How can I find particular number like xx and at what positon in my data file?
  1 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 6 月 24 日
What do you mean by "data file"? You have one variable, data, and it contains one integer in the range 1 to 1000000.

サインインしてコメントする。

回答 (1 件)

dpb
dpb 2021 年 6 月 24 日
You've answered the question (sorta') with your tag referencing find -- but...(there's almost always a "but", isn't there!!?? ) :)
With integers, it's trivial --
[ifound,idx]=find(data,MyWantedInteger);
will return the value MyWantedInteger and the location (first if more than one) of that value in the data array. IFF, of course, the value of the integer you ask for is included in the random sample of values in the particular instantiation of the randomized variates. The above code just generates a single value in the range between 1 and 100000 so the chances of picking that particular number aren't good in the above.
You don't say, so perhaps the idea is the above is a randomized value to find in some other array -- same idea, just different place to look --
[ifound,idx]=find(TheOtherDataArray,data);
Same caveats are true, the particular value would have to exist in that other data file or the result will return an empty variable for ifound, not the valud data nor a location.
That's all simple-enough with integers, with floating point numbers, unless you can type in every digit in the number you're looking for to reproduce machine precision of the double array in which the data array is stored (and including rounding to match how the rand() function rounds, the chances are essentially nil you'll match anything -- in that case you'll want to look into ismembertol to find values within some range of an input value.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by