2

How can I get the smallest n elements of a 1D array

example

A = [29, 60, 96, 43, 69, 53];
n=3;
%so B will be like this
B = [29 43 53];
1

1 Answer 1

4

Try this:

B = sort(A);    %# sort in ascending order
B = B(1:n);     %# take the first N-values
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.