How to make my code read the input values in appdesigner?

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

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!
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 ?
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.
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 ?
Global would work. Define global in opening function, define it in pushbutton callbacks, as well. Then set the values.
See this;
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.
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.
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
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.

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 18 Mar 2020

Commented:

on 18 Mar 2020

Community Treasure Hunt

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

Start Hunting!