How can I do this?

1 view (last 30 days)
Joao Joao
Joao Joao on 4 Jan 2022
Commented: Joao Joao on 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 Comments
Joao Joao
Joao Joao on 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

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (1)

Scott Satinover
Scott Satinover on 4 Jan 2022
Edited: Scott Satinover on 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 Comment
Joao Joao
Joao Joao on 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

Sign in to comment.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by