Find a range of minimum values in a vector/array

조회 수: 11 (최근 30일)
Alfredo Martini
Alfredo Martini 2013년 5월 6일
Hello everyone! Briefly, I would like to ask if, in MATLAB, exists a function or something else to find a min or max range of values in an array. I mean, if I have [7 2 1 4 34 9 8 5]
And I want to find the a "range" of three numbers, which is the minimumin the array, MATLAB will give me as result
[2 1 4]
And so on.
Thanks in advice, A.M.
  댓글 수: 2
José-Luis
José-Luis 2013년 5월 6일
What do you mean by "a range"? The three smallest numbers, or the three contiguous smallest numbers?
Alfredo Martini
Alfredo Martini 2013년 5월 6일
I mean the three contiguous smallest numbers. Forgive my english, is very poor.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 5월 6일
편집: Andrei Bobrov 2013년 5월 6일
I see two ways:
1)
out = sort(yourarray);
out = out(1:3);
2)
[ii,ii] = min(conv(yourarray,[1 1 1],'same'));
out = yourarray(ii-1:ii+1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by