For loop based on entries in Dataset

2 visualizaciones (últimos 30 días)
wessel ter Laare
wessel ter Laare el 20 de Ag. de 2020
Comentada: wessel ter Laare el 21 de Ag. de 2020
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 comentario
Rik
Rik el 20 de Ag. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Mohammad Sami
Mohammad Sami el 20 de Ag. de 2020
Editada: Mohammad Sami el 20 de Ag. de 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 comentario
wessel ter Laare
wessel ter Laare el 21 de Ag. de 2020
Good day sir,
Thanks for your reply, much appreciated. Works like a charm!
Rgrds,

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by