How to find unique elements in a vector without using unique or find?
4 ビュー (過去 30 日間)
古いコメントを表示
I have A=randi(100,1,100); How can I find unique values in array and show them without using unique() and find() .
5 件のコメント
John D'Errico
2016 年 10 月 24 日
Yes. It CAN be done using basic MATLAB statements.
For example, using sort, then diff and find will make it absolutely trivial. And if you cannot use unique, then sort, diff and find are off limits too.
But this is homework. You need to do your homework. There is simply no reason for this question under any other circumstances. It was assigned to you, for you to learn. If we doit for you then you learn nothing but how to get others to do your work.
Rena Berman
2017 年 1 月 20 日
編集済み: Image Analyst
2017 年 12 月 11 日
(Answers Dev) Restored Question.
I have
A=randi(100,1,100);
How can I find unique values in array and show them without using unique() and find() .
採用された回答
Massimo Zanetti
2016 年 10 月 23 日
編集済み: Massimo Zanetti
2016 年 10 月 23 日
Use an histogram based approach (works only for positive integers)
%get M random numbers from 1 to N
M=10; N=25;
A=randi(N,1,M)
%find unique values
x=1:N;
unique_vals = x(logical(accumarray(A',1,[N,1])))
その他の回答 (1 件)
Thorsten
2016 年 10 月 24 日
編集済み: Thorsten
2016 年 10 月 24 日
You can do this with for and if:
suppose you have the numbers in x
and want to generate the unique numbers in xu
pick the first number of x, this is your first unique number in xu
now run through all the number in x
check if it is in xu
if so, proceed with the next number of x
else, add the number to your unique numbers x
Voilá
This is a possible algorithm, and it is up to you to implement it, to learn something.
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!