How to check two unbalanced matrix?

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];

Respuestas (2)

Star Strider
Star Strider el 25 de En. de 2015
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 comentarios

sir, this my matrix:
a=[Columns 1 through 8
89.8731 79.3812 117.8973 32.8234 52.5252 24.9220 93.4288 86.0811
Columns 9 through 16
101.4806 14.7224 6.6336 100.5701 51.7163 91.1254 100.2094 38.9440
Columns 17 through 24
71.7236 96.1804 62.6327 38.1159 112.2841 109.5051 31.7090 74.1488
Columns 25 through 32
65.7694 94.7867 93.1744 54.0132 55.5098 122.1975 85.5061 96.3618
Columns 33 through 40
51.6636 99.8875 31.5059 86.1089 86.4142 127.3963 44.2550 58.4428
Columns 41 through 48
28.2850 31.3253 94.2205 102.1114 19.4583 32.4014 89.0007
51.7007];
b=[28.2850];
if 'b' is matching with 'a' than i have to display same value.
Z=[28.2850];
Star Strider
Star Strider el 25 de En. de 2015
I would use intersect, as I suggested in my original Answer. If ‘b’ is an element of ‘a’, then ‘Z’ will display it. If it is not, ‘Z’ will simply return an empty matrix.
Image Analyst
Image Analyst el 25 de En. de 2015
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
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.

Iniciar sesión para comentar.

Shoaibur Rahman
Shoaibur Rahman el 25 de En. de 2015
Another way may be:
X=[1;2;3;4;5];
Y=[2];
Z = X(X==Y)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de En. de 2015

Comentada:

el 25 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by