Removing specific position in array

I want to remove the element that are outside the starttime and endtime. Like for example it could be for the first 20 and last 5 entrys. I tried with the function nonzeros and it works for the time array, because the time array only have elements > 0, but not for the high. But I dont know how to remove it on a other way. Below is the Code that I use.
for j = 1:length(high)
if time(j)>= starttime && time(j)<=endtime
t(j) = time(j);
high(j) = high(j);
else
high(j) = [];
end
end
time = nonzeros(time);

 採用された回答

David Hill
David Hill 2022 年 5 月 3 日

0 投票

time(time<starttime|time>endtime)=[];

3 件のコメント

Lars Urban
Lars Urban 2022 年 5 月 3 日
Yes this is a easier way to eliminate in time the things that are outside thank you! But i still dont know how to get rid of the elements in high. The problem is every high has a time, so if i delete the first 2 in time i also want to delete that in high. My question was not specific enough sorry for that.
David Hill
David Hill 2022 年 5 月 3 日
high(time<starttime|time>endtime)=[];
time(time<starttime|time>endtime)=[];
Lars Urban
Lars Urban 2022 年 5 月 4 日
Thank you! It works!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by