How to find values for corresponding elements

조회 수: 2 (최근 30일)
Hazhan Majeed
Hazhan Majeed 2021년 4월 15일
댓글: Walter Roberson 2021년 4월 16일
Hello
I have a code that when applied to hourly discharge data, it gives the possition of peaks in the data serries. now i want to optain a peak time serries in a vector that has the same length of discharge but only have the peak discharges and the rest are NaN. can anyone help please?? i have included an example to clarify what i need
time(hr) Q given output(hr) wanted output
1 1 3 NaN
2 3 7 NaN
3 5 5
4 3 NaN
5 1 NaN
6 2 NaN
7 6 6
8 2 NaN
9 1 NaN

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 15일
wanted_output = nan(length(time_vector),1);
mask = islocalmax(Q);
wanted_output(mask) = Q(mask);
  댓글 수: 2
Hazhan Majeed
Hazhan Majeed 2021년 4월 16일
many thanks.
i also wanted to shange the length of given-output vector to be the same as length of Q. any idea how i can do that. thanks
Walter Roberson
Walter Roberson 2021년 4월 16일
given_output(end+1:length(time_vector)) = nan;

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by