필터 지우기
필터 지우기

How to clear graphical objects

조회 수: 19 (최근 30일)
Isaiah Slemons
Isaiah Slemons 2019년 5월 29일
댓글: Adam Danz 2019년 5월 30일
I have a local function inside of my script that runs a gui (not GUIDE, just uicontrol in a figure) and creates a polyshape based on the selection I make in a drop down menu (which references a spreadhseet of values). My issue is that everytime I click the drop-down to select a different row of data, the previous data is just overwritten and I can't figure out how to clear the data iteratively on each pass of the function after clicking the drop-down.
I'd like to be able to view the graph that I create without clearing it automatically. I tried to clear the variables that assign the polyshape but that doesnt work because its inside the local function. So once it runs it can't remove those variables because the caller workspace is reset (thats my understanding of it). Do I need to use a nested function to query mouseclicks? Thanks in advance
  댓글 수: 4
Geoff Hayes
Geoff Hayes 2019년 5월 29일
Isaiah - save the handle to the polyshape object and then delete it just prior to creating the new shape. You may need to post some of your code so that we can see its structure, but if the callback is nested within the main function then you should be able to do this. For example, you might have
function myGui
% create the GUI
% assign the callbacks
% define the handle to the polyshape
hPolyshape = [];
% in your drop down callback
function dropDownCallback(~,~)
% delete the old polyshape
if ~isempty(hPolyshape)
delete(hPolyshape);
hPolyshape = [];
end
% plot the polyshape
hPolyshape = polyshape(...);
end
end
The above is very rough and will not compile but it gives you an idea of what you can perhaps do.
Isaiah Slemons
Isaiah Slemons 2019년 5월 29일
Geoff,
Thank you so much for helping me out with this. I posted a little more information under Adams comment and a snippet of code. Thanks in advance for the help.

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

채택된 답변

Adam Danz
Adam Danz 2019년 5월 29일
편집: Adam Danz 2019년 5월 29일
Prior to drawing the updated ployshape, clear the axes using cla() and always specify the axis handle.
cla(axHandle);
ployshape();
If the axis handle is not already available in the function's workspace or in the "handles" input to the callback function, you can get the axis handle by passing it into the plotting function or using findobj() or findall().
Alternatively you could toggle the hold() status.
hold(axHandle, 'off')
ployshape()
hold(axHandle, 'on') %if necessary
  댓글 수: 4
Isaiah Slemons
Isaiah Slemons 2019년 5월 30일
Adam. This information is so valuable. Thank you very much for your help.
Adam Danz
Adam Danz 2019년 5월 30일
I'm glad it was helpful!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by