How Do I Extract User Inputs From a UIFigure?

조회 수: 17 (최근 30일)
Brandon
Brandon 2023년 7월 25일
답변: Brandon 2023년 7월 31일
I am trying to make a window with several checkboxes, and an OK button. I want the state of the checkboxes to be saved in memory when the user closes the window with the OK button. As soon as the figure closes, the data is gone. And I cannot figure out how to extract the data from the close function handle itself. Do I need to create a 'ValueChangedFcn' for each checkbox and change it in real time?

채택된 답변

Brandon
Brandon 2023년 7월 31일
I found my answer in another question: How do I pass variables from one GUI to another
The documentiation on GUI is especially lacking. setappdata() and getappdata() ought to be on the pages on buttons and checkboxes.

추가 답변 (2개)

Voss
Voss 2023년 7월 25일
To save the state when the uifigure is closed, specify a CloseRequestFcn for the uifigure that gets the state of each checkbox and saves that information to file (e.g., a mat file or a text file).
To restore the state when re-opening the uifigure:
  • if it's in an app, specify a startupFcn for the app that reads the file you saved and sets the state of the checkboxes
  • if it's not in an app, read the file in the script or function that creates the uifigure and set the state of the checkboxes when they are created
  댓글 수: 2
Brandon
Brandon 2023년 7월 26일
I need to user inputs to stay in memory while the program continues to run.
Voss
Voss 2023년 7월 26일
Maybe it is convenient to make the uifigure invisible instead of closing it in the closeRequestFcn. While it's invisible, the checkbox states are still available.

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


Brandon
Brandon 2023년 7월 26일
I resolved my issue by creating a global array. I can then declare the global array be used inside of the close function. I assign every checkbox value to my global array. I'm not very happy with this solution as it feels like a workaround.
My solution goes something like this:
global userSelect
userSelect = false*[1:10]
fig = uifigure(etc..)
cBoxList = {};
{Make checkboxes and put them into the cell array}
function closeIt(cBoxList,fig)
global userSelect
for i=1:10
userSelect(i) = cBoxList{i}.Value;
end
close(fig)
end

카테고리

Help CenterFile Exchange에서 Maintain or Transition figure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by