For loop based on entries in Dataset

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 Commento

Rik
Rik il 20 Ago 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.

Accedi per commentare.

 Risposta accettata

Mohammad Sami
Mohammad Sami il 20 Ago 2020
Modificato: Mohammad Sami il 20 Ago 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 Commento

Good day sir,
Thanks for your reply, much appreciated. Works like a charm!
Rgrds,

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by