Borrar filtros
Borrar filtros

I want to sort the positive integer values from a given values of real, rational, negative values in an array.

1 visualización (últimos 30 días)
I want to sort the positive integer values from a given values of real, rational, negative values in an array. Suppose, I have a=[0.2, 0.78, -3, 10, 0.8, -6, 2, -5, 3, 0.6, 8 ] then answer should be a= 10, 2, 3, 8.

Respuestas (3)

Adam
Adam el 22 de Sept. de 2016
tol = 1e-5;
a = a( a > 0 & abs( floor(a) - a ) < tol );
should work I think. Certainly it works on your example vector

Andrei Bobrov
Andrei Bobrov el 22 de Sept. de 2016
out = a(a > 0 & rem(a,1)==0)

KSSV
KSSV el 22 de Sept. de 2016
Editada: KSSV el 22 de Sept. de 2016
a(a>1)
Also read about find.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by