If I have a vector, e.g.
A = [ 2 8 6 5 3 3 6 5 5 3 4 1 2 9 6]
How do I return a vector which just gives single examples of the elements of A, e.g.
B = [1 2 3 5 6 8 9]
Kind regards,
Tom

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 12 日
編集済み: Azzi Abdelmalek 2014 年 2 月 12 日

0 投票

B=unique(A)
You can make the result without sorting
B=unique(A,'stable')

6 件のコメント

Tom
Tom 2014 年 2 月 12 日
Thanks!
Tom
Tom 2014 年 2 月 12 日
Related to this. If I think have a vector like:
B = [1 2 3 5 6 8 9]
How would I go about having a for loop run through only the elements of B?
Tom
Tom 2014 年 2 月 12 日
Bearing in mind B could be different every time....
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 12 日
It's not clear
Tom
Tom 2014 年 2 月 12 日
Sorry.
If I have a vector e.g.: B = [1 2 3 5 6 8 9]
I want to look through the elements of B
i.e. I tried:
for j = B
do something
end
But this doesn't seem to work...
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 12 日
That's depends on what (do something) is

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by