How to make my code read the input values in appdesigner?
1 次查看(过去 30 天)
显示 更早的评论
farzad
2020-3-18
Hi all
I am making an application that should get some input values from UI. But then should run some mfiles that need to know those values. What should I do ? make those variables global ? how ?
9 个评论
Mehmet Ziya KESKIN
2020-3-18
Call the function(mfiles) from the callback of the UI element. Something like;
funToCall(uin1,uin2)
There is a lot of ways to do it I suggest you search for it!
farzad
2020-3-18
Thank you , but the mfile I am calling is a main file and is not a function. should I make it a function ? I did run(filename)
and put the
global input1
in both the mfile and under UI call function, is that wrong ?
Mehmet Ziya KESKIN
2020-3-18
If the your script is non-related to your app, I dont think global would work. Instead use
getappdata/setappdata
or
assignin
to base. Using a function is always better I think, and would solve your problems easily.
farzad
2020-3-18
ok , since I am doing it from appdesigner, I get the input from one pushbutton , but I should pass it through another push button, should be be global between them ? how ?
Mehmet Ziya KESKIN
2020-3-18
Global would work. Define global in opening function, define it in pushbutton callbacks, as well. Then set the values.
See this;
farzad
2020-3-18
编辑:farzad
2020-3-18
Thank you very much
I am having a problem with the push button , shall you please help me first with this ? cause this is the vlaue I need to pass :
my code in appdesigner :
% Button pushed function: ChooseDirectoryButton
function ChooseDirectoryButtonPushed(app, event)
global currentFolder
app.ChooseDirectory.value=uigetdir;
currentFolder= app.ChooseDirectory.value;
cd(currentFolder)
and throught the other button I do :
% Button pushed function: StartButton
function StartButtonPushed(app, event)
run(filename)
end
But when I press the StartButton , I get the Error :
No appropriate method, property, or field 'ChooseDirectory' for class 'app1'.
Error in app1/ChooseDirectoryButtonPushed (line 15)
app.ChooseDirectory.value=uigetdir;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 309)
Error while evaluating Button PrivateButtonPushedFcn.
Mehmet Ziya KESKIN
2020-3-18
Try starting with the basics, may be a tutorial. There exist syntax error in your code like
% app.ChooseDirectory.value
app.ChooseDirectory.Value
You can't set a directory(string) to a value etc. Try sth like this, I havent tested;
function ChooseDirectoryButtonPushed(app, event)
global currentFolder;
currentFolder = uigetdir;
function StartButtonPushed(app, event)
global currentFolder;
assignin('base','currentFolder',currentFolder);
goFolder = strcat(currentFolder,'\filename.m');
run(goFolder);
I am not really familiar with app designer, you may find more resources if you work with GUIDE.
farzad
2020-3-18
Dear Mehmet , I would've not got to this point without your help , app designer is the same as GUIDE but only has made things a bit easier to handle, but the code is exactly the same in both.
still with your solution I get the same error. Somehow it's like pushbutton can not pass the ugetdir into the code
farzad
2020-3-18
The problem in both cases is the Push buttons. I changed the ChangeDirectory push button to Edit Field Text, and it worked smoothly.
but then the Start button did nor run the mfile
Attempt to execute SCRIPT Fsolver as a function:
E:\filename.m
Error in app1/StartButtonPushed (line 18)
run(filename)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 309)
Error while evaluating Button PrivateButtonPushedFcn.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)