What is an alternative FIND function that find indices and values of both ZERO and NONZERO elements in Matlab ?
Show older comments
Hello,
I am using Matlab and I would like to know how to find indices/values of both zero and nonzero elements of a given vector ? Can anyone help ?
For example:
X = [1 0 2; 0 1 1; 0 0 4];
How can I find indices of the elements in the first raw i.e. '1'; '0'; '2' ?
Thank you!
3 Comments
Walter Roberson
on 2 Feb 2016
You want to know the indices of everything together regardless of the respective value? Or you want two outputs, one for the non-zero values and one for the zero values?
Are you looking for linear indices or for row and column indices?
Kirby Fears
on 2 Feb 2016
Accepted Answer
More Answers (1)
Image Analyst
on 3 Feb 2016
Try this:
X = [1 0 2; 0 1 1; 0 0 4]
[zeroRows, zeroColumns] = find(X == 0)
[nonZeroRows, nonZeroColumns] = find(X ~= 0)
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!