フィルターのクリア

How to determine the position of an integer

1 回表示 (過去 30 日間)
Vivekram
Vivekram 2013 年 5 月 9 日
Hi,
I have a very basic question. I have a variable containing 5 numbers, say for eg,
d= [1 4 3 2 5]
how can i find the position of the number 3 in this d. I tried to use Find but I think I am using it wrong . Can anyone help me out please.
Thanks,
Vivekram

採用された回答

John Doe
John Doe 2013 年 5 月 9 日
編集済み: John Doe 2013 年 5 月 9 日
If you want to use the find function:
pos = find(d==3);
  1 件のコメント
Vivekram
Vivekram 2013 年 5 月 9 日
Hi Robert,
Ya , I tried it out but unfortunately the values are in cell format. Thereby giving me an error saying:
Undefined function or method 'eq' for input arguments of type 'cell'.
Can you suggest a way?
Thanks

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

その他の回答 (2 件)

Jim O'Doherty
Jim O'Doherty 2013 年 5 月 9 日
Hi Vivekram,
I'd sugget using the "unique" command
[C, ia, ic]=unique(d)
ic will give you the indices of the numbers in your array d
Jim
  1 件のコメント
Vivekram
Vivekram 2013 年 5 月 9 日
Hi Jim,
How will it give me the position of the digit 4 only? and the other thing that I forgot to mention is that the values are in a cell format.
Thanks

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


Grzegorz Knor
Grzegorz Knor 2013 年 5 月 9 日
編集済み: Grzegorz Knor 2013 年 5 月 9 日
If the values are in the cell format use cell2mat function:
pos = find(cell2mat(d)==3)

カテゴリ

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