Effacer les filtres
Effacer les filtres

constructing table using minimum values in loop

1 vue (au cours des 30 derniers jours)
Lee Borden
Lee Borden le 20 Avr 2021
Réponse apportée : Arun le 24 Fév 2024
I need to search through a database of survey responses to find the earliest week of responses for each responder, and construct a table of only the week they first responded
my loop so far looks like:
for i = 1:length(masq_ID)
id= masq_ID{i};
patient = masq01(strcmp(masq01.src_id, masq_ID(i)), :);
end
and an example patient table looks like:
ID reply1 reply2 reply3 reply4 week
'MG0270' 13 43 30 999 1
'MG0270' 14 44 30 999 0
I think I would need to use the min() function to construct the resulting table, but I don't know how to do this.
Thank you for your help

Réponses (1)

Arun
Arun le 24 Fév 2024
Hi Lee,
I understand that the requirement is to identify the earliest week of responses for each responder, each of whom has a unique ID. The need is to find the row with minimum value of week for an ID.
In the loop, after the patient table is formed for all the rows with the specified ID, add the following code to get the desired output:
% Find the row with the minimum value for 'week'
[minWeek, minIndex] = min(patient.week);
% Keep only the row with the minimum value
patient = filteredTable(minIndex, :);
This will help you to get the desired table.
For more information related to table please refer the documentation link: https://www.mathworks.com/help/matlab/tables.html
HTH

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by