필터 지우기
필터 지우기

I am trying to isolate the userdata associated with a time within a table and create an new table from the rows the of enteries associated with the selected time from the original table

조회 수: 1 (최근 30일)
I am trying to store the if true % Create a sample table ID = [38;43;38;40;49]; Date = {'02/03/2005'; '02/04/2005'; '02/05/2005'; '02/06/2005'; '02/07/2005'}; Time = {'22:00:00-06:00' ; '23:00:00-06:00'; '21:00:00-06:00'; '23:00:00-06:00'; '20:00:00-06:00'}; UserData = [124; 109; 125; 117; 122]; T = table(ID,Date,Time,UserData); A = table; % Iterate through rows of table for i = 1:1:height(T) % Check if first two characters are 23 if strcmp(T.Time{i}(1:2), '23') % Return the rows with 23 to a new table ids1 = find(T.Time(:,1)==23) ; for iii = 1:numel(ids1) A = [A; Tk(ids1(iii),:)]; end disp(i); end end
end
The string comparison is unable to return the rows into the new table A.

채택된 답변

Bharath Rangaswamy
Bharath Rangaswamy 2016년 4월 22일
Hi Nichelle,
I understand that your what to copy the rows with time '23:00:00-06:00' to A.
you can do it in the following way:
ID = [38;43;38;40;49];
Date = {'02/03/2005'; '02/04/2005'; '02/05/2005'; '02/06/2005'; '02/07/2005'};
Time = {'22:00:00-06:00' ; '23:00:00-06:00'; '21:00:00-06:00'; '23:00:00-06:00'; '20:00:00-06:00'};
UserData = [124; 109; 125; 117; 122];
T = table(ID,Date,Time,UserData);
ids1 = find(strcmp(T.Time(:,1),'23:00:00-06:00'));%finding all the rows with '23:00:00-06:00'
A = T(ids1,:);%Coppy those row in to A
Hope this help.
-Bharath

추가 답변 (1개)

Nichelle'Le Carrington
Nichelle'Le Carrington 2016년 4월 23일
Thank you, this cuts a lot of the runtime down by directly using the index without the forloop iterations.
Best wish to you.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by