Unable to see uifigure object properties

조회 수: 6 (최근 30일)
Victoria
Victoria 2025년 1월 24일
편집: Adam Danz 2025년 1월 24일
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
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
Victoria
Victoria 2025년 1월 24일
My uifigure has 3 tabs, the above is on the first tab, hence why it's defined. Screensize is [1 1 1280 720]
The above is nested within a create tab1 function

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

답변 (1개)

Adam Danz
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.
  1. rbBar and rbLine are defined in a function workspace
  2. Immediately after creating rbBar and rbLine you can see the object summaries display in the command window.
  3. These object summaries have links including "Show all properties".
  4. 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.
  1. Pass the handle as an output from the function or in a property. This is the preferred solution.
  2. 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 =
RadioButton (Line Graph) with properties:
Value: 1
Text: 'Line Graph'
Position: [10 5 105 30]
Show

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by