how fined vector index

1 回表示 (過去 30 日間)
lech king
lech king 2021 年 1 月 18 日
コメント済み: lech king 2021 年 1 月 22 日
I have a vector of 60,000 x 1, each part containing the values 0-9
What do I need to do to find out in which cells, for example, the value is 1?
The goal is to have an index of cells equal to 1
  4 件のコメント
Jan
Jan 2021 年 1 月 19 日
@ARK: Please post this as an answer, not as a comment. Then we can vote for it and select it as accepted asnwer.
Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni 2021 年 1 月 20 日
@Jan I didn't know whether OP wanted a more complicated solution, so I just suggested this simplified version to see if it'll serve their purpose. I'll put it up as the answer.

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

採用された回答

Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni 2021 年 1 月 20 日
Even though OP says "cells", based on their response to my comment, it seems that they were talking about simple vectors after all. In which case the following code:
myVector = randi([0,9],60e3,1); % vector of 60,000x1 containing integers between 0 and 9
linearIdx = find(myVector == 1); % linear indices of elements equal to 1
will work (in the second line, 1 can be substituted for whatever number is required).
It would be a good idea to look at ind2sub if you plan to also use matrices (instead of just vectors) some day.
Also, most applications support logical indexing, which is faster and uses less memory than linear indexing, so maybe look that up too.
  1 件のコメント
lech king
lech king 2021 年 1 月 22 日
Thank you Thank you very much

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by