Run m files by using GUI

조회 수: 1 (최근 30일)
Dogus Unlu
Dogus Unlu 2011년 7월 31일
I need to run m file from the push button by using GUI and enter some variables before the run.How can I apply these by GUI? There is a loop in the m file. Is that a problem for the GUI application? I will be appreciated with your answers. If there is a simple example, I will be so satisfied.
With best regards.

채택된 답변

Paulo Silva
Paulo Silva 2011년 7월 31일
m files can be scripts or functions, scripts (group of MATLAB statements) you just run them by writing their name, functions you also execute by writing their name but you can also provide arguments and provide outputs.
Please refer to your MATLAB documentation
doc scripts %execute this to learn about scripts
Also this:
doc functions %execute this to learn about functions
No problems with loops if you know what your are doing, I can't help you more with just the details you provided.
  댓글 수: 11
Jan
Jan 2011년 8월 7일
@Dogus: There is usually no good reason to store entered variables in "the" workspace - btw. which workspace do you mean? Each function uses its own workspace...
Dogus Unlu
Dogus Unlu 2011년 8월 13일
@Jan: Thanks for all your answers. I have solved the problem. I have been trying to improve the code to be effectively used with the GUI.

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

추가 답변 (1개)

Jan
Jan 2011년 7월 31일
You describe the one and only use of a GUI. Any GUI is used to define values and start a program, otherwise it is not a GUI, but a picture or a message box.
I suggest to read Matt Fig's 41 GUI examples.
[EDITED] This is my small example:
A trivial example - save this as an M-file:
function myFirstGUI
figure;
ValueH = uicontrol('Style', 'edit', 'String', '0', ...
'Position', [10, 100, 100, 24]);
StartH = uicontrol('Style', 'PushButton', 'String', 'Start', ...
'Position', [10, 50, 100, 24], ...
'Callback', {@myFunction, ValueH});
function myFunction(ButtonH, EventData, ValueH)
S = get(ValueH, 'String');
Data = sscanf(S, '%g', 1);
plot(1:10, rand(1, 10) * Data);
[EDITED] End of my small example - @Dogus: Can you see it?
  댓글 수: 5
deniel munthe
deniel munthe 2012년 6월 12일
i thing if you just want to run mfile in gui, you just call the function.m; it's will automaticly run your mfile
Fa'
Fa' 2012년 7월 19일
Hi all!! I have to run mfile in gui too. I don't understand where I have to call the function, probably in the callback of the button related?

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

카테고리

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