Run m files by using GUI

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일

1 개 추천

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

Dogus Unlu
Dogus Unlu 2011년 8월 1일
First of all, thanks for your reply. The problem that I need to solve is briefly, to run m file from the GUI push button. But need to enter values that is used as variables in the m file. The problem is to define the entered values to be used in the subsequent code. 3 variables are entered and are used in the code that is activated by the push button by help of GUI.
With best regards.
Jan
Jan 2011년 8월 1일
@Dogus: I've posted a GUI which solves your problem for 1 value. It is easy to expand it to 3 values. Did you accept Paulo's answer because it has solved your problem?!
Dogus Unlu
Dogus Unlu 2011년 8월 2일
Thanks, Jan for your peply. I can not accept your answer because there is not an option to accepot your answer on the page. Paulo's answer did not solve my problem. I am new to Matlabcentral webpage. I accept Paulo's answer accidentally..Where did you post the GUI example?
with best regards.
Jan
Jan 2011년 8월 2일
@Dogus: Ok. I've posted the examples some lines below... It would be helpful if you ask much more specifically.
Dogus Unlu
Dogus Unlu 2011년 8월 2일
@Jan: I have 3 variables to be entered to run an m file from the GUI screen. These variables will be used in the RUN.m file which must be activated by push button in GUI. By the way, I can not see your example code. Could you please post it to me mail address?dogus8555@gmail.com
With best regards.
Jan
Jan 2011년 8월 2일
@Dogus: You cannot see my example code??? It appears a few lines below this message and is called "function myFirstGUI". I will add some marks around it now - please tell me, if you still cannot find it.
Your descritpion still does not contain enough useful information. What is "the GUI screen"? Did you create it programmatically or per GUIDE? What is "the RUN.m"? And how can we help you exactly? Where is a loop in which M-file and why do you assume, that this is a problem?
Dogus Unlu
Dogus Unlu 2011년 8월 3일
@Jan: I see your example. I will try to run that code.Jan, I have written a code which contains for loops and convergenge checks. When the criteria is satisfied, the code will stop. RUN.m file is the main code which contains other m files to be executed. I need to visualize the code in a basic way with the GUI. GUI screen means the the screen that the values needed to be entered. I have created it per GUIDE.I need a way to enter the values to be used as variable in a code. If you give your mail to me, I can post the GUI figure to you.
With best regards.
Jan
Jan 2011년 8월 3일
@Dogus: I definitely do not like to be contacted by email. This is a public forum and its benefit is, that others can profit from published answers also. I spend enough time in this forum with helping others voluntarily. For work outside this sparetime activity, I'm writing invoices.
Do not use the name "run" as name of a function, because it is an important built-in function. Seeing your FIG-file will not help much. Better describe, what is not working as you want actually. You can create 3 Edit fields with GUIDE and forward the handles to the callback function, which is started when the button is pressed. As in my example, this callback function get the strings from the Edit fields and converts them to numbers and finally it calls the actual calculator.
Dogus Unlu
Dogus Unlu 2011년 8월 6일
@Jan:Thanks for all the answers, Jan. I have an addititonal problem.I can enter values and use the entered values in a simple function like yours(RAND(x,y)). But in my case, the entered values must be used in the m file. These entered values must be saved as a variable in the workspace. How can I do that?
With best regards.
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일

1 개 추천

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

Dogus Unlu
Dogus Unlu 2011년 8월 1일
Thanks for your answer. I have written a code needs variables to be entered from the screen by using the INPUT option in matlab.After entering the values, the m file code start to run. I want to convert this application in a more effective visual interface. I really be appreciated by your answer and a simple example.
With best regards.
Dogus Unlu
Dogus Unlu 2011년 8월 3일
@Jan: I can see the example. Thanks..
nurliana aqilah
nurliana aqilah 2012년 6월 12일
can anyone help me??i'm still cannot run mfile in gui..please..i don't understand how to use the command. i try to use open('filename') but it just open it not run it automatically
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?

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by