現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)