フィルターのクリア

Identify an array of arbitrary minimum values. Alternatives to min / find ?

3 ビュー (過去 30 日間)
Jamie
Jamie 2013 年 4 月 18 日
I would like to identify the occurences (index) of an arbitrary value within a Vector. The values I wish to identify will be close to but may not be exactly equal to this value.
For example having obtained the vector [Vector,t] = lsim(G,u,t) I would like to identify those points where the Vector assumedly intersects a horizontal line of given amplitude plot([X1 X2],[Y1 Y1])
I can obtain the first value quite simply with something along the lines of
[index value] = min(abs(abs(Vector) - abs(arbitrary_value)))
The find function is of some assitance however it requires that the arbitrary value equals the value of an element within the Vector exactly. Hence Idxs = find(A==MinValue) does not return a value within proximity of the intersection (or any point for that matter)
I thought I might be able to scrape by with a for loop i.e.
for i = 1:length(Vector)
if (Vector(i) - arbitrary_value) < tolerance
index(k) = i;
Value(k) = y(i);
k = k+1;
end
end
however it is far from an attractive or precise solution.
Any suggestions would be welcome.
Regards

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 4 月 18 日
編集済み: Andrei Bobrov 2013 年 4 月 18 日
eg:
tolerance = 1e-3;
ii = abs(Vector - arbitrary_value) < tolerance;
Value = Vector(ii);
index = find(ii);
ADD variant
t = vin - av;
idx = cellfun(@(x)strfind(sign(t(:).'),x),{0,[-1 1],[1 -1]},'un',0);
x0 = bsxfun(@plus,[idx{2:end}],(0:1)');
[~,ii] = min(abs(t(x0)));
iout = sort([[idx{1}],x0(sub2ind(size(x0),ii,1:size(x0,2)))]);
index = vin(iout);
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2013 年 4 月 18 日
See ADD part in my answer.
Jamie
Jamie 2013 年 4 月 19 日
Superb. Many thanks for your assitance

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by