how to deletes rows after a certain row

I got a 100*1 matrix and i sort them as descendibg order. After that i want to delete the worse half of the matrix to get a 50*1 matrix how could i get it?

 Réponse acceptée

Star Strider
Star Strider le 6 Avr 2018
Try this:
Data = randi(99, 100, 1); % Create Data
Sorted_Data = sort(Data, 'descend'); % Sort Descending
Keep_Data = Sorted_Data(1:50); % Data To Be Kept

3 commentaires

Berkay Can
Berkay Can le 6 Avr 2018
Modifié(e) : Berkay Can le 6 Avr 2018
Actually i have to detail my problem cause your answer worked but not as i want. İ got a 25*3 matrix right now and i sort them as descending order based on the third column. right now i want to delete the worst %50. i tried it as:
half = size(island1,1)/2; %to get the hal of the number of rows
island1_best = island1(1:round(half));
but i just got the first column of my matrix as a row :/
thank you anyway :D
island1_best = island1(1:round(end/2),:);
assuming that it was sorted on the first column
Berkay Can
Berkay Can le 6 Avr 2018
Thank you so much it worked :D Appreciated you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by