how to find Place on non zero values in matrix?
1 次查看(过去 30 天)
显示 更早的评论
hey all
i need to find places of 1's in matrix A:
A = [0,0,0,1,0,0,1,1,0;0,0,1,0,0,0,0,0,1;0,0,0,0,1,0,0,0,0]
result = {[4,7,8];[3,9];5}
please help
0 个评论
采纳的回答
更多回答(2 个)
javad ebrahimi
2018-3-5
HI dear Tha saliem
I hope that I have been able to understand what you mean, and the following code can help you
clc;clear;close all
A = [0,0,0,1,0,0,1,1,0;0,0,1,0,0,0,0,0,1;0,0,0,0,1,0,0,0,0];
B=find(A~=0)
size=size(A)
[Row,Col]=ind2sub(size,B)
result={Col(Row==1),Col(Row==2),Col(Row==3)}
Jan
2018-3-5
A = [0,0,0,1,0,0,1,1,0;0,0,1,0,0,0,0,0,1;0,0,0,0,1,0,0,0,0]
result = cellfun(@find, num2cell(A, 2), 'UniformOutput', 0)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!