use only data within a certain range in a calculation

21 ビュー (過去 30 日間)
Joe Duncan-Duggal
Joe Duncan-Duggal 2018 年 7 月 16 日
編集済み: Adam Danz 2018 年 7 月 16 日
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 件のコメント
jonas
jonas 2018 年 7 月 16 日
Please provide the data set or part of the data set, ideally with an example of the desired output

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

採用された回答

Adam Danz
Adam Danz 2018 年 7 月 16 日
編集済み: Adam Danz 2018 年 7 月 16 日
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,:)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by