Remove values below/above limits in first row of 2byx array and related values in second row.

I have two row-vectors. One relates to time values (datenums), the other related data at those timestamps. I wish to remove all values before and after a time AND remove related data values.
Working on just the time data is easy as it is in chronological order so I can obtain the values I require.
I have tried creating an array with the vectors and removing the values in the same way. This does not remove the related data values (long shot).
How can I do this? Assume time in row 1 and data row 2.
thanks
Mark

 Réponse acceptée

time=1:10
values=rand(1,10)
idx=time>5 & time <8
new_time=time(idx)
new_values=values(idx)

Plus de réponses (1)

Use logical indexing on the rows, and : (colon) to remove the whole rows:
data = [(datenum(2015,6,22):datenum(2015,7,22))' (1:31)'] %example data
%find rows before 30th June or after 15th July
toremove = data(:, 1) < datenum(2015,6,30) | data(:, 1) > datenum(2015,7, 15);
data(toremove, :) = []

1 commentaire

I believe this is similar to the above but more condensed. I already had datenum limits defined and the first solution removes the requirement for 2d array creation. thanks

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by