constructing table using minimum values in loop
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Arun
on 24 Feb 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
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!