column number extract using find function..

3 ビュー (過去 30 日間)
인수 송
인수 송 2022 年 5 月 6 日
コメント済み: Jon 2022 年 5 月 6 日
A = [ 0 500 1000 1500 2000 2500 3000 3500 x1 x2 x3 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 ] ;
i want to know the column number using find function about 500,1000,2000,3000, x2, 4000, 5000, 6000, 7000, 8000, 9000, 10000 ].
like above answer B
: B = [ 2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ] ; (example : it's not answer)
The x1, x2, x3 is variable value.

回答 (3 件)

dpb
dpb 2022 年 5 月 6 日
Use the optional second output form of find
[r,c]=find(....);
  1 件のコメント
Jon
Jon 2022 年 5 月 6 日
編集済み: Jon 2022 年 5 月 6 日
I think this seems like it would only help you if you had a 2d array of logicals or 0's and 1's. The OP just has a 1d array. Unless maybe I am completely missing something. The issue is how to create the corresponding vector of logicals that find can be applied to. One way is using ismember as shown in my answer below.

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


Jon
Jon 2022 年 5 月 6 日
A = [ 0 500 1000 1500 2000 2500 3000 3500 x1 x2 x3 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 ] ;
matchVals = [500,1000,2000,3000, x2, 4000, 5000, 6000, 7000, 8000, 9000, 10000 ];
B = find(ismember(A,matchVals))
  1 件のコメント
Jon
Jon 2022 年 5 月 6 日
In your case the values seem to follow a very regular progression. I'm not sure if this is just the case for the example you give or if it always holds. If you have such a regular progression you could also write a formulae, e.g
B = matchVals/500 + 1

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


Voss
Voss 2022 年 5 月 6 日
[~,idx] = ismember([500 1000 2000],[0 500 1000 1500 2000 2500])
idx = 1×3
2 3 5
  1 件のコメント
Jon
Jon 2022 年 5 月 6 日
Good point, you don't need to use find as I did after calling ismember, just use the second output argument to get the indices

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by