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.

 채택된 답변

Rik
Rik 2020년 5월 7일

1 개 추천

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

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
Rik
Rik 2020년 5월 7일
  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.
Idan Cohen
Idan Cohen 2020년 5월 8일
편집: Idan Cohen 2020년 5월 8일
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');

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

질문:

2020년 5월 7일

편집:

2020년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by