Hi guys i need some help with my code. im trying to delete a plot line but mathlab doesnt let me.
if ventilst== 1
%Weißer Hintergrund
xbodenw1 = [-500 -500 -498 -498];
ybodenw1 = [-115 -815 -815 -115];
p1= plot([-9735 -375], [-875 -875], 'k');
assignin('base','p1',p1);
p2= evalin('base','p2');
delete(p2)
end
if ventilst== 0
p2= plot([9735 -375], [-875 -875], 'k');
assignin('base','p2',p2);
p1= evalin('base','p1');
delete(p1)
end

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 4 月 23 日

0 投票

You have no hold on in what you show. When hold is not on (or equivalent internal settings) then each plot() call effectively calls cla() before doing the plotting, which would have the effect of deleting the existing line.
Try
if ishandle(p2); delete(p2); end

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

タグ

質問済み:

2019 年 4 月 23 日

回答済み:

2019 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by