Sample selection from a table
20 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
2022-11-8
Use rng('suffle') to randomize the random number generator (based on time)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!