use only data within a certain range in a calculation

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

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개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2018년 7월 16일

편집:

2018년 7월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by