How can i filter a table with several variables
    44 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hey guys,
i have a table with four rows: String, String, Datetime and Double. I want to generate a new table with all four rows filtered by a startdate and a enddate that i can analyse for example just 10 years (2000-2010).
Thank you :) 
1 件のコメント
  MarKf
      
 2023 年 1 月 3 日
				%% sample data
dates = datetime - years(5:5:40)' + hours(randn(8,1));
doublesx = randn(8,1);
strings1 = ('a':char('a'+7))';
strings2 = ('m':char('m'+7))';
example_table = table(strings1,strings2,dates,doublesx)
%% new table selct
idx = (example_table.dates.Year >= 2000) & (example_table.dates.Year < 2010);
new_table = example_table(idx,:) %even if 3rd position dates
P.S. Actual or faux example table .mat file or generating code shared would be appreaciated and make it easier to help. You likely mean for example 4 colums and many row entries, but in case you do have a horizontal table it'd work all the same. Also the number of variables does not matter. You could also convert it to a timetable using table2timetable and then use timerange  
採用された回答
  Voss
      
      
 2023 年 1 月 3 日
        
      編集済み: Voss
      
      
 2023 年 1 月 3 日
  
      % an example table with four columns:
dt = datetime(2023,1,(1:10).');
A = string(rand(10,1));
B = string(rand(10,1));
C = rand(10,1);
t = table(A,B,dt,C)
% a logical array to be used as a filter (keep data from dates between 
% Jan 3, 2023 and Jan 7, 2023, inclusive):
startDate = datetime(2023,1,3);
endDate = datetime(2023,1,7);
idx = t{:,3} >= startDate & t{:,3} <= endDate
% create the new table from just those dates:
new_t = t(idx,:)
0 件のコメント
その他の回答 (1 件)
  Steven Lord
    
      
 2023 年 1 月 3 日
        If you turned your table into a timetable using table2timetable you could use a timerange to index into the rows of that timetable.
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Data Preprocessing についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



