find non zero elements put in a matrix

i have a matrix and i want to take the row number of every non-zero element per collumn into a new matrix

답변 (1개)

Wayne King
Wayne King 2013년 12월 5일

0 개 추천

A = randi([-2 2],20,10);
idx = find(A~=0);
B = A(idx);
B contains all the nonzero elements of A, but how will you know the size of the matrix ahead of time?

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2013년 12월 5일

답변:

2013년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by