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?

 Accepted Answer

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 Comments

Berkay Can
Berkay Can on 6 Apr 2018
Edited: Berkay Can on 6 Apr 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
Thank you so much it worked :D Appreciated you.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!