How do I get MATLAB to automatically create a vector of unique values based on a known vector of values?

2 次查看(过去 30 天)
Let's say I have a vector of known values:
A = [10;20;30;100;200;10;20;30;40;50];
I'm looking for a way to get MATLAB to automatically create vector B of unique values, based on A.
So for the 7 unique values in A, B = [1;2;3;4;5;6;7]
Is there a way to make this happen?

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-10-17
编辑:Azzi Abdelmalek 2013-10-17
A=[10;20;30;100;200;10;20;30;40;50];
B=1:numel(unique(A))

更多回答(1 个)

Walter Roberson
Walter Roberson 2013-10-17
B = 1 : length(unique(A));

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by