필터 지우기
필터 지우기

Matrix reduction to see how many various elements the matrix has

조회 수: 2 (최근 30일)
Homayoon
Homayoon 2016년 2월 1일
편집: Stephen23 2016년 2월 1일
Dear All,
I have a 1*12 row whose elements are integers. Some of the elements might be repeated. I need to reduce the matrix to a smaller one which just contains the non-zero numbers disregarding of how many time they have been repeated.
for an Example
A = [4, 0, 0, 1, 4, 4, 2, 0, 1, 3, 9, 0]
The desired output is something like
Reduced = [ 4, 1, 2, 3, 9]
Please note that 0 should be excluded. Thank you so much for the help.

채택된 답변

Stephen23
Stephen23 2016년 2월 1일
편집: Stephen23 2016년 2월 1일
You could use unique with the 'stable' option:
>> A = [4, 0, 0, 1, 4, 4, 2, 0, 1, 3, 9, 0];
>> unique(A(A~=0),'stable')
ans =
4 1 2 3 9

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by