Effacer les filtres
Effacer les filtres

How can I do this?

1 vue (au cours des 30 derniers jours)
Joao Joao
Joao Joao le 4 Jan 2022
Commenté : Joao Joao le 6 Jan 2022
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
Jan
Jan le 4 Jan 2022
The question is not clear. Would this script solve the problem?
sin(2.17)
Joao Joao
Joao Joao le 4 Jan 2022
My program is like that:
function [ST] = add_patient(ST)
tempname = input ('Enter the name of the patient you want to add: ','s');
newPID= ['P',num2str(str2double(ST(end). Patient_ID(2:end))+1,'%08.f')];
newSNS= input('Enter the patient's NHS number: ');
while length (newSNS)~=9 %SNS_Numbers Size Check
warning('Invalid number, number must be 9 digits long')
newSNS= input('Enter the patient's NHS number: ');
end
newBirthday = input('Enter the patient's date of birth(MM/DD/AAAA): ','s');
[newBirthday] = date_check(newBirthday);%Function that checks for impossibilities in dates
reply = input(['Is this your date? ',newBirthday,' Nota: Form is MM/DD/AAAA\n Yes(1)/No(2): '],'s');
if isempty(reply) %Checking if the date is correct
reply = 1;
end
while reply == 2
newBirthday = input('Enter the patient's date of birth: ','s');
[newBirthday] = date_check(newBirthday);
reply = input(['Is this your date? ',newBirthday,' Nota: Form is MM/DD/AAAA\n Sim(1)/Não(2): '],'s');
if isempty(reply)
reply = 1;
end
end
newWeight = input('Enter the patient's weight(kg): ');
newHeight = input('Introduction to patient height(m): ');
boolnH = newHeight;
while boolnH > 10 %Warning for if the height is greater than 10 meters (Probable lack of '.')
warning(['You entered as height, in meters, ',num2str(newHeight),'. Do you want to proceed?'])
reply = input ('Yes(1)/No(2): ','s');
if isempty(reply)
reply = 1;
end
if reply == 2
newHeight = input('Introduction to patient height(m): ');
boolnH = newHeight;
else
boolnH = 1;
end
end
newCOPD = input('the patient has POTD?. Yes(1)/No(2)','s');
if isempty(newCOPD)
newCOPD = 1;
end
if newCOPD == 2
newCOPD = 'No';
elseif newCOPD == 1
newCOPD = 'Yes';
end
ST (end+1) = struct('Patient_ID',newPID,'SNS_Number',newSNS,'Name',tempname,'Birthday',newBirthday,'Weight_kg',newWeight,'Height_m',newHeight,'COPD',newCOPD,'CTR','-');
end
I have an excel file with patient data (weight, height, illnesses, etc). This function adds a new patient with new data. Now I to create a new script that exemplifies the use of this function.
Thanks for helping

Connectez-vous pour commenter.

Réponse acceptée

Scott Satinover
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
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.
Joao Joao
Joao Joao le 6 Jan 2022
Thank you so much. It helped

Connectez-vous pour commenter.

Plus de réponses (1)

Scott Satinover
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.
  1 commentaire
Joao Joao
Joao Joao le 4 Jan 2022
This program was provided to me. The program is like that:
function [ST] = add_patient(ST)
tempname = input ('Enter the name of the patient you want to add: ','s');
newPID= ['P',num2str(str2double(ST(end). Patient_ID(2:end))+1,'%08.f')];
newSNS= input('Enter the patient's NHS number: ');
while length (newSNS)~=9 %SNS_Numbers Size Check
warning('Invalid number, number must be 9 digits long')
newSNS= input('Enter the patient's NHS number: ');
end
newBirthday = input('Enter the patient's date of birth(MM/DD/AAAA): ','s');
[newBirthday] = date_check(newBirthday);%Function that checks for impossibilities in dates
reply = input(['Is this your date? ',newBirthday,' Nota: Form is MM/DD/AAAA\n Yes(1)/No(2): '],'s');
if isempty(reply) %Checking if the date is correct
reply = 1;
end
while reply == 2
newBirthday = input('Enter the patient's date of birth: ','s');
[newBirthday] = date_check(newBirthday);
reply = input(['Is this your date? ',newBirthday,' Nota: Form is MM/DD/AAAA\n Sim(1)/Não(2): '],'s');
if isempty(reply)
reply = 1;
end
end
newWeight = input('Enter the patient's weight(kg): ');
newHeight = input('Introduction to patient height(m): ');
boolnH = newHeight;
while boolnH > 10 %Warning for if the height is greater than 10 meters (Probable lack of '.')
warning(['You entered as height, in meters, ',num2str(newHeight),'. Do you want to proceed?'])
reply = input ('Yes(1)/No(2): ','s');
if isempty(reply)
reply = 1;
end
if reply == 2
newHeight = input('Introduction to patient height(m): ');
boolnH = newHeight;
else
boolnH = 1;
end
end
newCOPD = input('the patient has POTD?. Yes(1)/No(2)','s');
if isempty(newCOPD)
newCOPD = 1;
end
if newCOPD == 2
newCOPD = 'No';
elseif newCOPD == 1
newCOPD = 'Yes';
end
ST (end+1) = struct('Patient_ID',newPID,'SNS_Number',newSNS,'Name',tempname,'Birthday',newBirthday,'Weight_kg',newWeight,'Height_m',newHeight,'COPD',newCOPD,'CTR','-');
end
I have an excel file with patient data (weight, height, illnesses, etc). This function adds a new patient with new data. Now I to create a new script that exemplifies the use of this function.
Thanks for helping

Connectez-vous pour commenter.

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!

Translated by