How do I program push button to request user input and insert it into array?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Golnar
el 13 de Mzo. de 2014
Comentada: Joseph Cheng
el 17 de Mzo. de 2014
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={};
0 comentarios
Respuesta aceptada
Joseph Cheng
el 13 de Mzo. de 2014
Editada: Joseph Cheng
el 13 de Mzo. de 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 comentarios
Joseph Cheng
el 17 de Mzo. de 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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!