필터 지우기
필터 지우기

constructing table using minimum values in loop

조회 수: 1 (최근 30일)
Lee Borden
Lee Borden 2021년 4월 20일
답변: Arun 2024년 2월 24일
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

답변 (1개)

Arun
Arun 2024년 2월 24일
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by