user define dialog box or GUI

Hi all,
I wrote a function in Matlab that asks input from the user. I used this script and similar four times:
prompt = {'Enter the Value of a on SIDE 2','Enter the Value of b on SIDE 2','Enter the Value of c on SIDE 2'};
dlgtitle = 'Calculate ZReal - ZReal=a(Z[V])^2+b*(Z[V])+c';
definput = {'6.1101e-9','-2.3062e-04','17.372'};
opts.Interpreter = 'tex';
temp = inputdlg(prompt,dlgtitle,[1 140],definput,opts);
a=str2num(temp{1});
b=str2num(temp{2});
c=str2num(temp{3});
This dialog box do the job, but I'm looking for something easier and nicer. I thought about using GUI, but I don't know how to start the GUI from a function, get the data and close the GUI.
I will appreciate your help.
Thanks.

 Accepted Answer

Rik
Rik on 7 May 2020
Easier and nicer might be mutually exclusive.
If you want tips and examples about GUI design, I encourage you to check out this thread.

3 Comments

Thanks. I wish I saw that earlier.
I found the uicontrol and wrote
uicontrol('Style','Text',...
'Units','Normalized',...
'Position',[0.05 .55 .1 .1],...
'String','Enter a',...
'CallBack','uiresume(gcbf)');
It is working great.
Another three question if I may:
  1. How can I change the font (color, size etc.)?
  2. Is it possible to set a defualt number inside the text box?
  3. Is it possible to add another line in the same textbox?
Thanks
  1. Look through the documentation page with the uicontrol properties. There are a lot of them, and I know at least the size can be changed, I would have to look up Color.
  2. No, but you can set the String property when you create the element to anything you like, which I would argue is the same effect as a default.
  3. With some of the uicontrol styles you can set the Max property to something higher than 1 and set a cell array as the String property to have multiple lines of text. You can even set Max to inf. Note that for an edit field this will stop the callback from working as intended.
Glad to be of help.
If my answer solved your issue, please consider marking it as accepted answer.
The way to do that, if someone will read, for question 1 (2 and 3, still working to find the answer)
You specify one of the uicontrol as variable:
test==uicontrol('Style','Text',...
'Units','Normalized',...
'Position',[0.05 .55 .1 .1],...
'String','Enter a',...
'FontSize',[12],...
'CallBack','uiresume(gcbf)');
for color - set(a1_text,'ForegroundColor','blue');
for bold - set(Side_1,'FontWeight','bold');

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2019a

Tags

Asked:

on 7 May 2020

Edited:

on 8 May 2020

Community Treasure Hunt

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

Start Hunting!