Taking only the first element

I have matrix =[0,2 ;0,25 ;0,25;0,3] And I am using find function To get the index of every element The error occur when the search value is 0,25 it give an output [2,3] And I want to take only the first element of the output array Or the second element

5 件のコメント

KSSV
KSSV 2020 年 5 月 26 日
Read about ind2sub and sub2ind.
Shehab Tarek
Shehab Tarek 2020 年 5 月 26 日
I just want to take the first index
Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2020 年 5 月 26 日
Hello
This is simple, find allows you to return a certain number of values, if you only want the first then specify like this
a = find (a==0.25 , 1);
Then, you will only have the first occurrence of the value 0.25.
Hope this helps. You can read more about find here:
https://uk.mathworks.com/help/matlab/ref/find.html
Shehab Tarek
Shehab Tarek 2020 年 5 月 26 日
Thank you 🙏
Tommy
Tommy 2020 年 5 月 26 日
To get only the nth index:
matrix = [0.2 ;0.25 ;0.25;0.3];
n = 2;
allIdx = find(matrix==0.25,n);
nIdx = allIdx(end);

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2020 年 5 月 26 日

コメント済み:

2020 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by