For loop based on entries in Dataset

5 views (last 30 days)
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 Comment
Rik
Rik on 20 Aug 2020
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.

Sign in to comment.

Accepted Answer

Mohammad Sami
Mohammad Sami on 20 Aug 2020
Edited: Mohammad Sami on 20 Aug 2020
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 Comment
wessel ter Laare
wessel ter Laare on 21 Aug 2020
Good day sir,
Thanks for your reply, much appreciated. Works like a charm!
Rgrds,

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!