How to get values ​​from multiple columns based on the values ​​of one column ?

조회 수: 8 (최근 30일)
elliot brooksbank
elliot brooksbank 2021년 8월 19일
편집: Adam Danz 2021년 8월 27일
i have an 85x3 double dataset made up of months, years and timestamps. i want to extract the values from all 3 columns based on month e.g december/12 then create a new variable with just the selected data in the columns that correspond with 12 for years 2007-2014
  댓글 수: 1
Adam Danz
Adam Danz 2021년 8월 19일
Since you described the data as double precision, your timestamps must be numeric instead of datetime. Any reason for that? Datatime values are usually more easy to work with. How are you timestamps represented as numeric values?

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2021년 8월 19일
편집: Adam Danz 2021년 8월 27일
This is how I imagine your data are organized based on your description.
% [year, month, data, ...]
data = [repelem((2007:2014)',12,1), repmat((1:12)',8,1), rand(96,5)]
data = 96×7
1.0e+03 * 2.0070 0.0010 0.0010 0.0001 0.0004 0.0008 0.0002 2.0070 0.0020 0.0001 0.0006 0.0003 0.0004 0.0008 2.0070 0.0030 0.0000 0.0002 0.0003 0.0000 0.0001 2.0070 0.0040 0.0002 0.0005 0.0003 0.0003 0.0002 2.0070 0.0050 0.0008 0.0009 0.0003 0.0010 0.0003 2.0070 0.0060 0.0003 0.0007 0.0010 0.0008 0.0005 2.0070 0.0070 0.0005 0.0003 0.0009 0.0009 0.0007 2.0070 0.0080 0.0005 0.0006 0.0004 0.0002 0.0006 2.0070 0.0090 0.0007 0.0009 0.0001 0.0007 0.0010 2.0070 0.0100 0.0002 0.0001 0.0004 0.0001 0.0000
Get all values from column 3 and month 12 with months in column 2 of the data.
% v-months v-column 3
vals = data(data(:,2)==12, 3)
vals = 8×1
0.3673 0.0875 0.5953 0.4585 0.6260 0.8043 0.1210 0.4608

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by