How do I program push button to request user input and insert it into array?

2 Ansichten (letzte 30 Tage)
I'm creating a GUI w/ two push back buttons: 'Existing Patient', and 'New Patient'. To program New Patient, I want the GUI to request user input for NAME and DOB, and insert it into an array. How do I do this?
My empty array:
patient(2).name={}; patient(2).dob={}; patient(2).date={}; patient(2).percentages={[]}; patient(2).notes={};

Akzeptierte Antwort

Joseph Cheng
Joseph Cheng am 13 Mär. 2014
Bearbeitet: Joseph Cheng am 13 Mär. 2014
It all depends on whether you want the prompt within GUI or popup question to show up. Perhaps the function inputdlg() would work for the popup version.
example:
%once 'New Patient' has been selected (insert similar lines into the new patient pushbutton callback section)
prompt = {'Enter New Patient''s Name:','Enter Patient''s DOB:'};
% need to use double '' to get the single ' to show up in a string;
promptname = 'Entry for New Patient';
numlines = 1;
defaultanswer = {'Doe, John' , 'mm/dd/yyy'};
answer = inputdlg(prompt, promptname,numlines,defaultanswer);
%%insert into array
patient(2).name = answer(1);
patient(2).dob = answer(2);
% continue on-wards to get the rest of the process to enter the percentages or notes.
Now if the prompt is to be displayed within the same GUI interface, it gets a bit trickier, since the rest of the GUI is unknown to us. I would assume there would be some edit boxes for name and DOB. Just use the normal get() function For default GUIDE naming:
patient(2).name =get(handles.edit1,'String');
%where edit1 is the tag for the edit box where the new patient's name is to be entered.
patient(2).dob = get(handles.edit2,;'String');
%where edit2 is the tag for the edit box where the new patient's DOB is to be entered.
  3 Kommentare
Golnar
Golnar am 16 Mär. 2014
Joseph, for the 'Existing Patient' push button, I want the same pop-up, to enter the two pieces of info (NAME and DOB) and for it to search the arrays for it. These are my patient info arrays, are they set up correctly? I've left one blank for the New Patient.
Joseph Cheng
Joseph Cheng am 17 Mär. 2014
I do not think so. If these are copied into the command window you'll see that the john doe entries would be overwritten by Jane Doe's information. John Doe should be patient(1) and jane doe should be patient(2). Perhaps entries for new patient should not be a static number (here you are using 2) but appended to the current patient database. By using length(patient) we can get the number of entries currently in patient and for a new entry we would use patient(length(patient)+1). If you are pre-allocating the last entry to be blank, as you are doing here, then patient(end) would be for new entries.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by