필터 지우기
필터 지우기

How do I set up a uigetdir with a Push button in appdesigner ?

조회 수: 34 (최근 30일)
farzad
farzad 2020년 3월 18일
댓글: Adam Danz 2020년 3월 19일
Hi All
I need to have a push button that when I press, the uigetdir command activates and allows the user to choose the desired directory , and pass this to the main code that will be run via the app. I have been unsuccessful and I get errors
  댓글 수: 1
farzad
farzad 2020년 3월 18일
Could someone help ? I am searching everywhere , and no hope so far ! It's frustrating, cause appdesigner and GUI can't be tested in command prompt and I don't know why the edit field works but button with uigetdir not

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 3월 18일
Step 1: Add callback function to the Button
Right click the button from within appdesigner and add a callback function.
Step 2: add 'selectedPath' as a private property
This variable will store the user's selected path. You can name the variable anything you want.
From the Code View in appdesigner, go to the CODE BROWSER, select Properties, and press the green "+" button.
This will add a new private property. Rename it to selectedPath or whatever other name you want and set a default value. The default value will be used if this variable is accessed prior to the user choosing a path. The default value can be empty (selectedPath = '';). Add a commented description of the variable.
Step 3: Call uigetdir from the button's callback function
Call the uigetdir function from within the button's callback function. Choose which inputs you need. Store the output in app.selectPath using the same variable name as you declared as a private property.
function ButtonPushed(app, event)
app.selectedPath = uigetdir(); % <-- add this line
end
Step 4: Access the chosen path
From anywhere in your app, you can access the selected (or default) path by using
app.selectedPath
  댓글 수: 12
farzad
farzad 2020년 3월 19일
ok , it seems that it's the
assignin('base','currentFolder',currentFolder);
line that send the variable to matlab workspace, but still ,when the Mfile runs, it can not read it. I think it's a matter of time and velocity of execution.
should I use uiwait ? is it relevant ?
Adam Danz
Adam Danz 2020년 3월 19일
Have you switched from using global variables to using public properties? Global variables cause all sorts of problems.
Lots of problems can arise by using assignin(), too. I hadn't noticed that line in your code until you mentioned it. Again, declaring currentFolder as a public property is a better option. If you want to access the currentFolder variable from the base workspace, you could do so like this:
app = myApp; % myApp is the name of your app; this is how you open the app.
app.currentFolder

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Package and Share Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by