Data Selection/Sorting

1 visualización (últimos 30 días)
Curious Mind
Curious Mind el 9 de Nov. de 2019
Comentada: JESUS DAVID ARIZA ROYETH el 10 de Nov. de 2019
I have a column vector known as Data. Please see attached. I want to divide/sort this column vector into two (80% and 20%). I want the 80% to comprise the first largest/lowest values in 'Data' and the remaining 20% to comprise the next largest/lowest values. Any ideas? Thank you so much!

Respuesta aceptada

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH el 9 de Nov. de 2019
I hope this is what you are looking for:
data=[23 20 18 50 17 24 56 35 38 19 29 53 26]';
f=sort(data,'descend');
f2=reshape([f flipud(f)]',[],1);
vector80=f2(1:round(numel(data)*0.8))
vector20=f2(round(numel(data)*0.8)+1:numel(data))
Another interpretation of what I understood could be like this too:
data=[23 20 18 50 17 24 56 35 38 19 29 53 26]';
f=sort(data,'descend');
vector80=f(1:round(numel(data)*0.8))
vector20=f(round(numel(data)*0.8)+1:numel(data))
  2 comentarios
Curious Mind
Curious Mind el 10 de Nov. de 2019
Editada: Curious Mind el 10 de Nov. de 2019
Thanks for your comment. I made a typo in my post. It is actually a column vector not a row vector. Can this code be modified for the case of a column vetcor?
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH el 10 de Nov. de 2019
it works for both forms, if data is 1x13 then change it with data = data '; so that it is 13x1, and if you want to show the results as rows then add a single quote, for example: vector80 = f2 (1: round (numel (data) * 0.8)) '

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by