How can I do this?

4 visualizaciones (últimos 30 días)
Joao Joao
Joao Joao el 4 de En. de 2022
Comentada: Joao Joao el 6 de En. de 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 comentarios
Jan
Jan el 4 de En. de 2022
The question is not clear. Would this script solve the problem?
sin(2.17)
Joao Joao
Joao Joao el 4 de En. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Scott Satinover
Scott Satinover el 4 de En. de 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 comentarios
Scott Satinover
Scott Satinover el 5 de En. de 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 el 6 de En. de 2022
Thank you so much. It helped

Iniciar sesión para comentar.

Más respuestas (1)

Scott Satinover
Scott Satinover el 4 de En. de 2022
Editada: Scott Satinover el 4 de En. de 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 comentario
Joao Joao
Joao Joao el 4 de En. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by