How to save index of Values of an item in a matrix?

5 次查看(过去 30 天)
I have a matrix of of elements like
[0,0,0,1,0,0,0,0,1,0,1]
I'd like to go through the matrix and at each element where the value is greater than zero, I want to save the index to a new matrix such that the new matrix looks like:
[4, 9, 11]

回答(1 个)

Dyuman Joshi
Dyuman Joshi 2023-3-17
x=[0,0,0,1,0,0,0,0,1,0,1];
y=find(x>0)
y = 1×3
4 9 11

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by