How can I do this?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Scott Satinover
2022-1-4
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 个评论
Scott Satinover
2022-1-5
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.
更多回答(1 个)
Scott Satinover
2022-1-4
编辑:Scott Satinover
2022-1-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!