For loop based on entries in Dataset

조회 수: 2 (최근 30일)
wessel ter Laare
wessel ter Laare 2020년 8월 20일
댓글: wessel ter Laare 2020년 8월 21일
Good day,
I have a dataset in Matlab with 100,000 or so rows, and about 50 columns. First column is Date ('dd-mm-yyyy hh:mm' format), second column is Name, and remainder of the columns are all information captured at that specific time.
I can use a for loop and interate through all line, as follows:
for i = 1:size(Name,1)
end
But it while take a long time to run. So to reduce compiling time, i would like to first pre-set names (Axel, Leon, Louis, Harvey) and set a fixed date range (say 01-01-2020 -till 01-02-2020). I want to neglect all lines outside of this date range, and afterwards want a for loop where first all lines with Name Axel are evaluated, and output is created. Than all lines with Name 'Leon', etc. etc.
(Was thinking a double for loop with For Axel, For these dates do .... next but couldn't figure it out)
Needless to say I am not an expert in Matlab (yet).
Thanks in advance for your kind assistance.
Rgrds,
  댓글 수: 1
Rik
Rik 2020년 8월 20일
You will have to parse all lines and extract the date and name. Your idea would then only make sense if the parsing of the rest of the row is very time-intensive.
For those names: store them in a cell array and you can trivially loop through each name.

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

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 8월 20일
편집: Mohammad Sami 2020년 8월 20일
I assume you have loaded the data in MATLAB. You can use function "contains" to get the index of rows that contain the names. You can use the comparison with date time to filter the date. E.g
if true
Idx = T.Date > datetime(2020,1,1) & T.Date < datetime(2020,2,1);
Namelist = {'Axel' '....'};
Idx2 = contains(T.Name,Namelist,'IgnoreCase',true);
T = T(Idx & Idx2,:);
  댓글 수: 1
wessel ter Laare
wessel ter Laare 2020년 8월 21일
Good day sir,
Thanks for your reply, much appreciated. Works like a charm!
Rgrds,

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by