How to check two unbalanced matrix?

조회 수: 2 (최근 30일)
Matlab111
Matlab111 2015년 1월 25일
댓글: Star Strider 2015년 1월 25일
For example:
X=[1;2;3;4;5];
Y=[2];
if this matched than i should get Z as matched value like this
Z=[2];

답변 (2개)

Star Strider
Star Strider 2015년 1월 25일
I don’t understand what you are doing or what ‘matched’ means.
It would seem that the intersect function might be what you want:
Z = intersect(X,Y)
that would produce:
Z =
2
  댓글 수: 4
Image Analyst
Image Analyst 2015년 1월 25일
It may not work with floating point numbers if the numbers were arrived at in different ways. See http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Star Strider
Star Strider 2015년 1월 25일
True.
In that event, it would be necessary to use the R2014b version of round on both, or equivalently:
roundn = @(x,n) fix(x.*10.^n)./10.^n;
wnere x is the number (or matrix) to be rounded, and n the number of digits to be rounded to.

댓글을 달려면 로그인하십시오.


Shoaibur Rahman
Shoaibur Rahman 2015년 1월 25일
Another way may be:
X=[1;2;3;4;5];
Y=[2];
Z = X(X==Y)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by