to combine different vectors with the same element

In matlab, which command can combine different vectors, and form a new vector like a boolean merge,for example, I have three vectors,[1 2 3 4], [2 4 5],[ 1 5 6],by using this command, a new vector [1 2 3 4 5 6]is formed, where only one of the same elements is left and these element are in series from small to large

1 件のコメント

Stephen23
Stephen23 2016 年 2 月 21 日
See Star Strider's answer for the simplest solution.

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 21 日
編集済み: Azzi Abdelmalek 2016 年 2 月 21 日

0 投票

out=union([1 2 3 4], union([2 4 5],[ 1 5 6]))
%or
out=union([],cat(2,[1 2 3 4], [2 4 5],[ 1 5 6]))'

1 件のコメント

DEHUA SHI
DEHUA SHI 2016 年 2 月 21 日
Thanks very much! It is very helpful

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

その他の回答 (1 件)

Star Strider
Star Strider 2016 年 2 月 21 日

2 投票

A completely unique experience:
three_vectors = [[1 2 3 4], [2 4 5],[ 1 5 6]];
new_vector = unique(three_vectors)
new_vector =
1 2 3 4 5 6

2 件のコメント

DEHUA SHI
DEHUA SHI 2016 年 2 月 21 日
I really appreciate your help
Star Strider
Star Strider 2016 年 2 月 21 日
My pleasure!

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

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by