Reputation: 265
I have a figure window on MATLAB. I want the user to type in his answer on that figure window. The code I am using is :
> prompt = {'Your Age: '}
> dlg_title = 'Bio data'
> answer = inputdlg(prompt,dlg_title)'
This is the figure which I am getting.
My Questions :
1) How to make the age, which I type in this dialogue box, appear up at a specific position ON my figure window once I click on "ok" button of this dialogue box.
2) How to put up a customized background on this dialogue box.
3) How to get the user input ON the figure window without the dialogue box. like shown in the picture given bellow : (so that answer is typed on the horizontal line and vertical line is the cursor)
Upvotes: 4
Views: 2865
Reputation: 4336
This might be close to what you want,
function age = AgeDB()
f = figure;
set(f,'Position',[200 350 350 150],'Color',[.4 .6 .4],'MenuBar','none',...
'Name','Bio data','Visible','off');
bc = [.4 .6 .4];
ht = uicontrol('Style','text','Position',[30 80 160 40],...
'String','Your Age:','FontSize',20,'FontWeight','bold',...
'BackgroundColor',bc,'ForegroundColor','w');
he = uicontrol('style','edit','Position', [200 80 120 40],...
'BackgroundColor',bc,'FontSize',20,'FontWeight','bold',...
'ForegroundColor','w','Callback',{@Age_Callback});
hp = uicontrol('Style', 'pushbutton', 'String', 'Ok',...
'Position', [150 10 50 20],...
'Callback', 'close');
movegui(f,'center')
set(f,'Visible','on')
waitfor(he)
function Age_Callback(hObject,eventdata)
age = str2double(get(hObject,'string'));
end
end
Upvotes: 4