You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to make my code read the input values in appdesigner?
1 view (last 30 days)
Show older comments
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 Comments
Mehmet Ziya KESKIN
on 18 Mar 2020
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
on 18 Mar 2020
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
on 18 Mar 2020
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
on 18 Mar 2020
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
on 18 Mar 2020
Global would work. Define global in opening function, define it in pushbutton callbacks, as well. Then set the values.
See this;
farzad
on 18 Mar 2020
Edited: farzad
on 18 Mar 2020
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
on 18 Mar 2020
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
on 18 Mar 2020
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
on 18 Mar 2020
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.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)