フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by