フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by