How to take the maximum value of an array?

조회 수: 2 (최근 30일)
arina octave
arina octave 2015년 2월 25일
댓글: Star Strider 2015년 2월 25일
Hi, I have this array a = [1:20]. How do I take the maximum value of every 5 elements of it. So I will have b = [5 10 15 20]. Anyone can help me? Thank you.

채택된 답변

Star Strider
Star Strider 2015년 2월 25일
This works:
a = [1:20];
b = max(reshape(a, 5, []));
  댓글 수: 6
arina octave
arina octave 2015년 2월 25일
and I'm truly amazed with your answer.. aaa thank you so much Star Strider!
Star Strider
Star Strider 2015년 2월 25일
My pleasure!

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

추가 답변 (1개)

Greig
Greig 2015년 2월 25일
Try something like this...
a=1:20;
steps = 5;
b = NaN(mod(length(a)/steps,steps), 1); % preallocate b for speed, if you want to run larger loops
count = 1; % an index count for b in the loop
for ii = 1:steps:length(a)-(steps-1)
inds = ii:ii+(steps-1); % The indices we are interested in
b(count) = max(a(inds)); % Get the max
count = count+1; % add 1 to the counter
end
  댓글 수: 1
arina octave
arina octave 2015년 2월 25일
hi, thank you for kindly answer my question. but what i want is the x axis of signal b exactly like the x axis of signal a. do you have any idea how to do that? thank you...

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by