Hello guys, i have a push button and I want to laod m-file when I press it, please answer ;)

I make a GUI and I want to add a push button that will load a m-file.

댓글 수: 2

Please explain further what you mean by "load" of an m file. Do you mean execute the file, or do you mean upload from somewhere to somewhere else?
I want to do something like this: upload data from m-file to workspace and then my Simulink simulation will downaload this data to run a simulation with this parameters.

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

 채택된 답변

under the callback of the button in the code of that gui, put something like this:
evalin('base','<your_m_file>')
This will run the m-file and load the variables in the matlab workspace! So not in the GUI workspace. If you want to have the variables in the local workspace of the GUI you can use, after the callback is finished the GUI workspace is deleted, so if you want to keep the values of the mfile in the GUI accessible you have to save them in the global structure (the handles structure by default):
eval('<your_m_file>')
also do not include the .m extension in the name.

댓글 수: 2

It is probably worth avoiding eval, and simply calling run instead.
I agree, eval can be dangerous. Use run instead

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

추가 답변 (1개)

Maciej Wroz
Maciej Wroz 2015년 10월 16일
편집: Maciej Wroz 2015년 10월 16일
I done as you told Dennie, thanks. Now I want to load m-file when I push my button and run Simulink simulation, when I use your code simulation are loading but not run, can you help my with this problem ?

댓글 수: 1

If I understand you correctly, it seems to me that you start the simulink simulation from the m-file, right ? If the m-file is run by the code in the gui, i suppose that the mistake is in the m-file itself. It could be that you use the wrong command to start the simulation. Try using sim() instead of open() or run(). For better help, you should upload the part of the code that currently does this, or give me some more information on what happens and what you would expect to happen.

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

카테고리

도움말 센터File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

질문:

2015년 10월 15일

댓글:

2015년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by