Sample selection from a table

조회 수: 20 (최근 30일)
Lucas Hayes
Lucas Hayes 2022년 11월 6일
댓글: Lucas Hayes 2022년 11월 8일
Hello everyone. I'm new to MATLAB, I'm stuck on something and can't find a solution. I would be grateful if you could help me.
I have a dataset showing hundreds of patient names and medical fees they paid to the hospital. What I have to do is randomly select a group of patients from the dataset and perform various mathematical operations on the fees they pay. Then I want to remove these selected patients from the dataset and select a new group of patients from the updated dataset.
I used the dataset as a table and converted the patient names to row names for the identification of the payments (I do not know if this is the best way to connect patients with their payments.). However, I cannot make the selections according to the patient's name. When I use the payments for selection, I cannot see which patient paid the selected fees at the end of the procedure.
I'm also trying to figure out how I can remove the patients selected in the first phase from the dataset later on. Please see a look of my dataset below.
Patient_Name Medical Fee
Patient1 250$
Patient2 402$
Patient3 132$
Patient4 85$
Patient5 208$
I would be very happy if you could share your thoughts on these two issues. I really appreciate any help you can provide.
Kind regards.

채택된 답변

Walter Roberson
Walter Roberson 2022년 11월 6일
편집: Walter Roberson 2022년 11월 8일
current_table = original_table;
%as long as there are enough entries in the table
while height(current_table) >= NumberToSelect
%random selection from what is left
rows_to_select = randi(height(current_table), NumberToSelect, 1);
%pull out those entries
current_selection = current_table(rows_to_select, :);
%delete the patient name
current_selection.Patient = [];
%do appropriate processing
Process_Selected_Entries(current_selection);
%remove the selected entries
current_table(rows_to_select,:) = [];
end
%current_table will have fewer than NumberToSelect rows in it at this
%point. Not enough entries to process, ignore them.
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 11월 8일
Use rng('suffle') to randomize the random number generator (based on time)
Lucas Hayes
Lucas Hayes 2022년 11월 8일
Thank you, I'll try it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by