필터 지우기
필터 지우기

removing rows from a timetable

조회 수: 73 (최근 30일)
Elizabeth Lees
Elizabeth Lees 2021년 3월 26일
댓글: Steven Lord 2021년 3월 26일
I want to remove the first year (1985) of data (12 rows as it is monthly data) from a timetable matrix. what is the easiest way to do this?

답변 (2개)

madhan ravi
madhan ravi 2021년 3월 26일
편집: madhan ravi 2021년 3월 26일
load combined_observed_vs_sim_timetable
combined_data(1 : 12, :) = [ ]
combined_data = 168×22 timetable
Date Observed_Rio_Branco Observed_Floriano_Peixoto Observed_Fazenda_Borangaba Observed_Bacaba Observed_Aruma_Jusante Observed_Canutama Observed_Labrea Observed_Seringal_Fortaleza Observed_Valparaiso_Montante Observed_Seringal_da_Caridade Observed_Manoel_Urbano Simulated_Rio_Branco Simulated_Floriano_Peixoto Simulated_Fazenda_Borangaba Simulated_Bacaba Simulated_Aruma_Jusante Simulated_Canutama Simulated_Labrea Simulated_Seringal_Fortaleza Simulated_Valparaiso_Montante Simulated_Seringal_Da_Caridade Simulated_Manoel_Urbano ________ ___________________ _________________________ __________________________ _______________ ______________________ _________________ _______________ ___________________________ ____________________________ _____________________________ ______________________ ____________________ __________________________ ___________________________ ________________ _______________________ __________________ ________________ ____________________________ _____________________________ ______________________________ _______________________ Jan-1986 1017 969.63 1349.9 1802 6968.7 10561 9772.3 6905.8 4304.6 2888.9 2076.7 559.83 732.66 1045.9 1872.9 10375 5828 5576.8 4237.3 2743 1872.5 1383.7 Feb-1986 1230.6 1830.1 1724 2647.1 8423.2 12426 10847 8811.1 5477.1 3967.5 2965.6 1018.1 1276 1290.3 1979 12589 8103.4 7833.7 6166.8 4248.9 2778.7 2047.2 Mar-1986 967.34 1840 1709.1 2929.3 13547 12834 11064 9360.4 5506.5 3509.2 2897.9 1129 1428.7 1258.9 1841.9 13774 9018.3 8723 6927.6 4991.6 3345.2 2442.8 Apr-1986 806.47 1263 1877.3 2846 17404 12920 11184 10054 6061.8 2886.3 1916.9 797.7 1075.2 978.77 1824 12595 7795.5 7482 5710.9 4088 2808.2 1915.8 May-1986 293.87 626.74 1151.5 2668.3 19464 12606 10787 6231.6 2891.5 1380.9 721.38 415.34 635.24 491.36 1402.7 9157.1 5217.9 4937.3 3443.1 2436.3 1637.9 930.86 Jun-1986 113.97 290.89 310.43 2173.6 19749 9329.1 6656.8 2421.8 1024.4 494.37 397.73 279.31 456.66 222.99 751.22 6395.5 3686.3 3456.4 2237.3 1596.2 1007.3 437.98 Jul-1986 83.097 134.22 196.55 1146.7 17103 3293.9 2458 1166 398.3 171.84 114.43 215.85 360.92 115.09 344.92 4721 2805.1 2617.9 1618 1159.4 690 225.64 Aug-1986 78.416 129.61 129.74 562.03 11957 1839.4 1575.4 895.49 306.07 125.81 89.861 174.67 294.66 62.785 174.53 3696.4 2223.8 2068.6 1238.8 890.4 505.66 122.85 Sep-1986 76.319 135.29 156.27 571.07 6949.5 1666.1 1413.4 867.31 353.05 156.67 109.37 144.07 245.14 35.887 94.731 3019.4 1823.4 1692.5 990.71 712.78 391.4 70.092 Oct-1986 100.75 118.7 200.94 549.16 5145.5 1742 1581.5 993.03 526.13 334.39 311.02 119.42 205.91 22.724 63.454 2661.8 1534.2 1421.6 818.02 586.69 315.16 41.187 Nov-1986 132.78 284.27 265.8 696.7 5852.8 1881.9 1790.1 1053.2 702.09 678.13 368.47 185.98 278.49 269.27 445.67 3815.9 2038.1 1938.4 1381.7 908.01 561.87 287.4 Dec-1986 311.8 683.23 809.84 1362.1 7161.6 5274.3 5180.8 4164.3 2837 2159.6 1194.1 361.42 488.24 652.51 1010.2 6179.4 3637.2 3516.5 2807.2 1873.1 1293 926.36 Jan-1987 703.97 1284.5 1333.1 1768.1 8527.8 9187 8415.3 6284.7 4345.4 2976.5 1731.3 402.92 556.37 908.3 1425.5 7716.6 4609.4 4469.3 3545.9 2268.8 1599.5 1169.7 Feb-1987 540.83 1293.7 1632 2545.4 10767 11981 10684 7222.1 3844.9 1940 1067.2 607.64 818.61 1401.3 1649.1 9676.1 6120.9 5979.9 4844.7 2908.3 1932.9 1373.7 Mar-1987 321.32 634.69 1605.3 3037.1 14944 12625 10880 6217.7 2440.1 1432.5 716.73 916.95 1208.1 1850.8 1849 12269 8163.1 7995.2 6502.2 3850.3 2418.7 1628.5 Apr-1987 396.5 514.03 1241.1 2816.8 18866 12031 9932 4864.4 2224.2 1562.3 1072.1 756.44 1064.3 1429.1 1946.1 12403 7682.5 7459.9 5666.6 3364.9 2059.7 1241.9

Steven Lord
Steven Lord 2021년 3월 26일
Do you want to remove the data from 1985 from your timetable or do you want to remove the first twelve rows from it? In this particular case it appears that those two operations would give the same result, but that may not always be the case.
v = (1:10).';
dt = datetime('now', 'Format', 'h:mm:ss a') + minutes(randi([30 90], 10, 1));
tt = timetable(dt, v)
tt = 10×1 timetable
dt v ___________ __ 10:40:38 PM 1 9:50:38 PM 2 10:24:38 PM 3 10:35:38 PM 4 10:28:38 PM 5 9:47:38 PM 6 10:38:38 PM 7 10:09:38 PM 8 10:05:38 PM 9 10:31:38 PM 10
Let's remove every row that takes place before 10 PM.
whatHour = hour(tt.dt);
tt(whatHour < 22, :) = []
tt = 8×1 timetable
dt v ___________ __ 10:40:38 PM 1 10:24:38 PM 3 10:35:38 PM 4 10:28:38 PM 5 10:38:38 PM 7 10:09:38 PM 8 10:05:38 PM 9 10:31:38 PM 10
For your application you would want to use the year function.
  댓글 수: 2
Elizabeth Lees
Elizabeth Lees 2021년 3월 26일
편집: Elizabeth Lees 2021년 3월 26일
thanks for the reply, and yes agreed this would not and may not always be the same. However in my dataset the datetime (which you express as dt) is already present in the timetable when I created it. Therefore I'm unsure how the remaining script you've suggested would work - currently I'm recieving the error message 'Input data must be a real, numeric array.' when using the years function and then also 'Error: Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.' when using the second line of code. When if not defining it to equal a new table I still get an error message stating 'Undefined function or variable 'WhatYear'.' This is how I've formatted by script for reference:
whatYear =years(combined_data)
test = combined_data(WhatYear < 1986, :)=[];
Steven Lord
Steven Lord 2021년 3월 26일
whatYear =years(combined_data)
combined_data appears to be your timetable array. You need to pass its times into years. Note when I called hours I called it not with tt as input but tt.dt, which is the datetime part of tt.
test = combined_data(WhatYear < 1986, :)=[];
Assign to test or delete rows from combined_data, not both simultaneously.
% either
% keep certain rows and make a copy
test = combined_data(WhatYear >= 1986, :);
% or delete rows and don't make a copy
combined_data(WhatYear < 1986, :)=[];
% or make a copy and then delete rows from the copy
test = combined_data;
test(WhatYear < 1986, :)=[];

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

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by