이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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 (한국어)