How can I make the difference or subtraction between two scalar vectors?

2 ビュー (過去 30 日間)
Mira le
Mira le 2021 年 5 月 6 日
コメント済み: Mira le 2021 年 5 月 6 日
Hello every one
I have vectors like
x1=[1 2 5 8 ]
x2=[2 1 0 6]
x1 - x2 = [5 8]
How can I get this result
if I do ; it will be [5 8 ] U [0] = [5 8 0] ???? also its problem
and do we choose value from vector or zero like:
rand([1 2 5 8 ], null) = 1 , then my new vector is [5 8 0 1]
Thank you

採用された回答

Stephen23
Stephen23 2021 年 5 月 6 日
編集済み: Stephen23 2021 年 5 月 6 日
x1 = [1,2,5,8];
x2 = [2,1,0,6];
setdiff(x1,x2)
ans = 1×2
5 8
"and do we choose value from vector or zero like"
It is not clear exactly what you want to achieve, but probably indexing is crucial:
For example:
N = numel(x1);
x3 = x1(randperm(N));
x3(randi(N)) = 0
x3 = 1×4
5 8 0 1
  1 件のコメント
Mira le
Mira le 2021 年 5 月 6 日
Thank you very mush for your answer, My goal to to generate another vector according to x1 and x2

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by