How to compare two vector with different dimension

2 ビュー (過去 30 日間)
Boni_Pl
Boni_Pl 2019 年 8 月 29 日
回答済み: Jos (10584) 2019 年 8 月 29 日
Hello, I have two vectors
x1 = [1;2;4;7;8];
y1 = [2;5;8;6;1];
which are coordinates of all zero and non zero values of a matrix. And then
x2=[2;8;7]
y2=[6;1;2]
are the coordinates of just the non-zero values. Then how to get the coordinates of zero values? Please help.
  5 件のコメント
the cyclist
the cyclist 2019 年 8 月 29 日
Boni_PI, I edited your question just a bit, using the CODE button to format your vectors.
Adam
Adam 2019 年 8 月 29 日
What are the other options than 'zero or non-zero' in your matrix?! surely that set should cover every element of the matrix?

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

回答 (1 件)

Jos (10584)
Jos (10584) 2019 年 8 月 29 日
I assume the elements of x and y are linked? Why is the first element of (x2,y2) than not in the list of coordinaties (x1,y1)? I assume this is a mistake.
If I were you, I would link the coordinates explicitly, as rows of a N-by-2 array, allowing to use SETDIFF:
xy_all = [x1(:) y1(:)]
xy_nonzero = [x2(:) y2(:)]
xy_zero = setdiff(xy_nonzero, xy_all, 'rows')

カテゴリ

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