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

조회 수: 2 (최근 30일)
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={};

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 3월 13일
편집: Joseph Cheng 2014년 3월 13일
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
Golnar
Golnar 2014년 3월 16일
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 2014년 3월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by