Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:08:40+00:00 2026-06-01T03:08:40+00:00

I have a new button in my GUI here is its callback: function ptlNew_ClickedCallback(hObject,

  • 0

I have a new button in my GUI here is its callback:

function ptlNew_ClickedCallback(hObject, eventdata, handles)  
% hObject    handle to ptlNew (see GCBO)  
% eventdata  reserved - to be defined in a future version of MATLAB  
% handles    structure with handles and user data (see GUIDATA)  
cla(handles.axes1,'reset');  
clear variables  

but the last line doesn’t work
what can I do to clear workspace of my GUI without closing it to feed up memory?
my variables are in handles structure
for example if I have variable X, I should access it in form handles.X
I made my variables properties of handle because I wanted to access them in more than one callback function and I didn’t want to make them Global

Also I tried to clear a specific variable. so instead of clear variables I used this line of code
clear handles.FiducialPixels
But it doesn,t work too and when I try to access it in the next line by code:
handles.FiducialPixels
it is printed on the Command Window quitely as it was before
I’m really confused what can I do?
The interesting issue is that line clear variables or clear handles.FiducialPixels don’t make any error or warning but they do their task!

As Li-aung Yip answered I changed the call back to this form:

function ptlNew_ClickedCallback(hObject, eventdata, handles)
names = fieldnames(handles);
rmfield(handles,'FiducialPixels');
names = fieldnames(handles)
handles.FiducialPixels  

but this is what appeares on the command line running lines 4 and 5:

names =

'figure1'
'pnlControlPointsImageCoordinates'
'uitoolbar1'
'pnlCalculateParameters'
'mnuInteriorOrientation'
'btnLoad2'
'edtImageFile'
'text17'
'edtInteriorOrientation'
'edtF'
'text16'
'edtYPPA'
'text15'
'edtXPPA'
'text14'
'text13'
'btnBrowseLensDistortion'
'edtLensDistortion'
'text12'
'btnBrowseInteriorFile'
'text11'
'axes2'
'uitoggletool3'
'uitoggletool2'
'uitoggletool1'
'ptlNew'
'txtCalculation'
'btnJumpTo'
'btnLoad'
'edtImagePath'
'text9'
'btnSaveParameters'
'btnCalculate'
'edtNumber'
'text8'
'uitable1'
'btnGinput'
'btnBrowse'
'edtFilePath'
'text1'
'btngrpTypeOfOrientation'
'axes1'
'mnuItemControlPointsImageCoordinates'
'mnuItemCalculateParameters'
'rdbtnProjective'
'rdbtnAffine'
'rdbtnConformal'
'output'
'TableData'
'TableDataEmpty'
'Matrix'
'FiducialImageCoordinates'
'dataH'
'FiducialPixels'
'flag'
'X'

592 handles.FiducialPixels

ans =

1.0e+003 *

7.5294    3.8246
0.1357    3.8723
3.9200    0.2311
3.8882    7.4499
7.4817    0.2311
0.2152    7.5294
0.2311    0.2311
7.4658    7.4817

You see handles.FiducialPixels still exists
Even if you use guidata(hObject,handles) after the third line, the result will be the same

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:08:41+00:00Added an answer on June 1, 2026 at 3:08 am

    If you want to delete absolutely every workspace variable, including all workspace (global) variables created by your script, and those variables created at the command prompt and those variables created by other scripts, just use:

    clear
    

    Using clear (every variable) is considered impolite, though. This is because a user might be doing some work on the command line before calling your script. When your script calls clear, all of his work is erased (forever!)


    If you want to delete handles.FiducialPixels – that is, a particular element of the handles struct – then clear is not what you want. Instead, use the rmfield() function, which is designed for deleting fields from structs.

    Homework: read the documentation pages for struct, and the functions for dealing with structs: cell2struct | deal | fieldnames | getfield | isfield | isstruct | namelengthmax | orderfields | rmfield | setfield | struct2cell | substruct.


    Edit(1): rmfield() does work. You are just not using it correctly.

    >> figure
    >> handles.h1 = uicontrol
    
    handles = 
    
        h1: 329.0011
    
    >> handles.h2 = uicontrol
    
    handles = 
    
        h1: 329.0011
        h2: 0.0016
    
    >> handles = rmfield(handles, 'h1')
    
    handles = 
    
        h2: 0.0016
    

    From doc rmfield:

    rmfield

    Remove fields from structure

    Syntax

    s = rmfield(s, 'fieldname')

    s = rmfield(s, fields)

    Description

    s = rmfield(s, 'fieldname') removes the specified field from the
    structure array s.

    s = rmfield(s, fields) removes more than one field at a time. fields
    is a character array of field names or cell array of strings.

    Note that the calling convention s = rmfield(...) indicates that rmfield returns something. In this case, the original structure s is not modified. Instead, rmfield() returns a new struct, without the fields you specified for deletion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that dynamically creates a new button through JavaScript that when
I have 2 radio button with values New & Existing. If user chooses New,
I have an app that when I click a button loads a new TabItem
I have a button that basically looks like this: <Button android:id=@+id/admin_new_questions android:layout_width=fill_parent android:layout_height=wrap_content android:text=See
I have a button that, when pressed, will add a new HTML row. Within
I am new to iphone development. I have created a button in the view.
I have a basic GUI (plain Jframe with a button) and I have changed
So -- here's my jam. I'm SUPER NEW (i.e. days) into Python and have
I have a Gui which allows the user to click a button and view
I have 4 buttons that when click starts a new activity class. This works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.