use only data within a certain range in a calculation

4 visualizzazioni (ultimi 30 giorni)
Hi, I am trying to limit the range of data (in a single column) used in a function by value, however I can only work out how to limit it by row.
Column 3 of the data table contains time in year format, and I would like to create a variable that is a column of only the years in a certain range.
Below is what I have tried to use.
t=station{2007.5:2012.0,3};
I am also trying to use other values within the row in the same function, so would need to be able to use the entire row, after selecting by t range
  1 Commento
jonas
jonas il 16 Lug 2018
Please provide the data set or part of the data set, ideally with an example of the desired output

Accedi per commentare.

Risposta accettata

Adam Danz
Adam Danz il 16 Lug 2018
Modificato: Adam Danz il 16 Lug 2018
I don't know if your year data are stored as integers or in datenum format but in any case, this logic should work.
Let's say your table is named 'data' and the year column is named 'year'. This code selects all years between 1979 (inclusive) and 1990 (not inclusive). The parentheses are not needed but I think they are helpful for perceptual grouping.
data = table([1950:2020]', 'VariableNames', {'year'});
idx = (data.year >= 1979) & (data.year < 1990);
selectedYears = data.year(idx);
In this example, the selection is the same as above but also includes years between 2000 and 2012. This time the parentheses are required in order to group the two sides of 'or'.
idx = (data.year >= 1979 & data.year < 1990) | (data.year >= 2000 & data.year < 2010)
selectedYears = data.year(idx)
You'll see that 'idx' are logical index values that select the rows that meet you year criteria. So if you want to select the entire row of the table,
data(idx,:)

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by