find all indices in a matrix
1 view (last 30 days)
Show older comments
Oday Shahadh
on 10 Jan 2017
Commented: Oday Shahadh
on 10 Jan 2017
How can I find all indices in a matrix to include the zero and non-zero elements? .Thanks
0 Comments
Accepted Answer
Walter Roberson
on 10 Jan 2017
find(ones(size(TheMatrix))
This is not typically useful. Instead you would normally use something like
[R, C] = ndgrid(1:size(TheMatrix,1), 1:size(TheMatrix,2));
and then R will contain row indices and C would contain column indices, so R(I,J) will always be I and C(I,J) will always be J. This is mostly used in a form such as
RC = [R(:), C(:)];
This can also be created as
[R, C] = ind2sub(size(TheMatrix), 1:numel(TheMatrix));
RC = [R(:), C(:)];
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!