How can I do this?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I hope you are doing well in this pandemic. I am new in matlab, and I would like to know how do I develop a script that exemplifies the use of a certain function. If you could give me an example of any function I would appreciate it. Thanks
2 commentaires
Réponse acceptée
Scott Satinover
le 4 Jan 2022
So the input argument is the table from the excel file. So this might work if the excel file is in the same folder as the function and this script:
file = 'filename'; % Use the name of the excel file, and omit the extention.
table = table2struct(readtable(file)); % The script updates a struct, so read in the excel file as a table and convert to a struct.
table = add_patient(table); % Run the function on the struct and update the table.
writetable(table,file); % Overwrite the excel file.
4 commentaires
Scott Satinover
le 5 Jan 2022
You need to retrieve the results for a given patient, and the results are found on the second tab. First, pull the results from the spreadsheet on the second tab using the name-value argument the specifies the sheet you want to retrieve, using the Sheet name-value argument. Without this argument, the readtable function only reads the first sheet, so you need to specify it here:
file = "Data";
exams = readtable(file,Sheet=2);
The readtable function returns most text in cells as part of a cell array, which you can't sort or filter data with. But the data you want to retrieve is based on data that is a cell array. To work around this, convert the PatientID column into a string array with the string function:
exams.PatientID = string(exams.PatientID);
Now, filter your results and create a new table. Specify the patient ID as a string, and then use logical expressions to filter your results. For example, if you want to look up the records for P00000008, enter this:
ID = "P00000008";
filtered_exams = exams(exams.PatientID == ID);
Then, to return the latest entry, use index notation on the filtered table:
filtered_exams(end,:)
To learn more about this functionality, go through the MATLAB Onramp and MATLAB Fundamentals training.
Plus de réponses (1)
Scott Satinover
le 4 Jan 2022
Modifié(e) : Scott Satinover
le 4 Jan 2022
I recommend you take a look at this category:
If you want a more interactive learning experience, take a look at the MATLAB onramp tutorial:
It's super helpful for learning the basics of MATLAB.
Voir également
Catégories
En savoir plus sur Startup and Shutdown 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!