Unable to see uifigure object properties
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi,
I'm very new to Matlab, I'm basically learning as I go. At the moment I'm working on getting a callback function for a group of two radio buttons to work. The aim of the buttons is to switch between a line graph and a bar graph. The buttons are created fine, and open in the figure but I can't see the properties.
My script:
chartSwitchGroup = uibuttongroup(tab, 'Position', [30, screenSize(4) - 330, 1220, 40],'BorderType','none');
rbLine = uiradiobutton(chartSwitchGroup, 'Text', 'Line Graph', 'Position', [10, 5, 105, 30], 'Value', true, 'FontSize',16);
rbBar = uiradiobutton(chartSwitchGroup, 'Text', 'Bar Chart', 'Position', [115, 5, 125, 30], 'FontSize',16);
rbBar
rbLine
Command window:
I'm just trying to see the properties, basically so I can see what they are and learn more but even when leaving the figure open, I still get the 'no longer exists message'
rbBar =
RadioButton (Bar Chart) with properties:
Value: 0
Text: 'Bar Chart'
Position: [115 5 125 30]
Show all properties
rbLine =
RadioButton (Line Graph) with properties:
Value: 1
Text: 'Line Graph'
Position: [10 5 105 30]
Show all properties
Unable to display properties for variable rbLine because it no longer exists.
**EDIT: More intense googling suggests this could be something to do with nested functions? **
댓글 수: 2
Giacomo
2025년 1월 24일
Hi Victoria,
I think it would be fine to past how you've defined "tab" and "screensize", to get proper help.
BR,
Giacomo
답변 (1개)
Adam Danz
2025년 1월 24일
편집: Adam Danz
2025년 1월 24일
Let's see if I understand your workflow. Please correct me if this summary is incorrect.
- rbBar and rbLine are defined in a function workspace
- Immediately after creating rbBar and rbLine you can see the object summaries display in the command window.
- These object summaries have links including "Show all properties".
- After execution leaves the function workspace that defines rbBar and rbLine, you click on "Show all properties". This results in a messaging stating that the object no longer exists.
The issue describe above happens when a variable is defined and stored in one workspace but an attempt is made to access the variable in another workspace. In this case, the variable is created in a function workspace and you are trying to access it in the base workspace (doc: Base and Function Workspaces).
There are two ways to access the object handle from the base workpace.
- Pass the handle as an output from the function or in a property. This is the preferred solution.
- Find the object using findobj or findall.
I have the sense that you're buidling this app within a function and not as a class. If that's the case one option is to store the handles in the figure object using setappdata. Here's an example.
fig = uifigure();
bgrp = uibuttongroup(fig);
rbLine = uiradiobutton(bgrp, 'Text', 'Line Graph', 'Position', [10, 5, 105, 30], 'Value', true, 'FontSize',16);
setappdata(fig, 'rbLine', rbLine)
As long as you have the figure handle fig, you can access the rbLine handle from outside of the function workspace using getappdata.
rbLine = getappdata(fig,'rbLine')
ans =
Value: 1
Text: 'Line Graph'
Position: [10 5 105 30]
Show
More info: Share Data Between Workspaces
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!