How to clear variable from GUI?

6 views (last 30 days)
Ibro Tutic
Ibro Tutic on 16 Jun 2017
Commented: Adam on 16 Jun 2017
I am plotting from a structure called I have a push button to clear all graphs and this structure to plot other things, but the clear command doesn't seem to be working. When I try to replot using the same code as before, I get an error saying "Subscripted assignment between dissimilar structures." When I check, I have a struct with no fields. How would I just remove the variable completely?
for i=1:length(handles.graphs)
catch ME
guidata(hObject, handles);

Answers (1)

Adam on 16 Jun 2017
Edited: Adam on 16 Jun 2017 = [];
will reset the field to empty (which is what I usually do because I use an isempty(...) test when using the data)
handles = rmfield( handles, 'data' );
would remove the field.
clear is used for clearing variables, you can't clear a field of a structure with it.
clear handles
would be valid syntax, but do not do this in a GUI as it will remove the whole structure and make your GUI unusable.
Adam on 16 Jun 2017
Well, after = [];
it doesn't contain anything, which was the point, as far as I could tell from your question.
You have posted any plotting code so I have no idea what that does, but if you are trying to plot what is in then I would assume you have run some code which populates it again after clearing it.

Sign in to comment.


Find more on View and Analyze Simulation Results in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!