フィルターのクリア

Find Unique values in array

5 ビュー (過去 30 日間)
Ali Tawfik
Ali Tawfik 2020 年 5 月 12 日
コメント済み: Ameer Hamza 2020 年 5 月 13 日
Hi all,
I am trying to create a new array contains ONLY the unique values (same values but not repeated) which in the following case are 90 0 45
I used unique function, however, the function also returns the same data as in x, but in sorted order. I DO NOT want them in sorted order,
Also, I would like to obtain the index of the unique values in the x
like index=[1,2,9]
clear all;
clc;
x=[90 0 0 90 90 90 90 90 45 0 0 0];
y=unique(x)

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 12 日
編集済み: Ameer Hamza 2020 年 5 月 13 日
clc;
x=[90 0 0 90 90 90 90 90 45 0 0 0];
[y, idx] = unique(x, 'stable')
output
y =
90 0 45
idx =
1
2
9
  4 件のコメント
Ali Tawfik
Ali Tawfik 2020 年 5 月 13 日
Hi,
Thanks for your prompt reply.
I understand, but I am looking for ONLY for index 1 and 4
So I wanna my output to be
z(:,:,1) = [10;20];
z(:,:,4)=[100;200]; which should be z(:,:,2)
Ameer Hamza
Ameer Hamza 2020 年 5 月 13 日
Try try something like this
idx = [1 4];
for i=1:numel(idx)
z(:,:,i)=A(:,:,idx(i))
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by