Hai,
I have drawn a few lines. At the later part of my program I need to delete (remove/erase) those lines, which do not satisfy the required conditions. So, is it possible to remove or erase the lines which have already been drawn, in matlab. Is there any function that supports this. Looking for your reply.
BSD

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 11 日

5 投票

f=figure(1);hold on;
c1=plot(1:10);
c2=plot(10:-1:1);
delete(c1);

1 件のコメント

Emir Akyildiz
Emir Akyildiz 2023 年 1 月 8 日
Thank you so much!

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2011 年 11 月 11 日

5 投票

If you want to clear just certain specific lines, you can keep track of all your line handles and clear them like Fangjun and Nick showed you. If you want to clear all lines from the axes, then call this function:
%=====================================================================
function ClearLinesFromAxes()
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearLinesFromAxes
If you want, you can pass in an argument via the argument list and use that instead of gca, which is the axes you used last.
function ClearLinesFromAxes(axesToClear)
axesHandlesToChildObjects = findobj(axesToClear, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearLinesFromAxes

4 件のコメント

Felix Crazzolara
Felix Crazzolara 2020 年 4 月 3 日
In Matlab 2018b this might change the scale of the plot. How can this be prevented? That is, how can lines be removed without the axis limits to change?
Image Analyst
Image Analyst 2020 年 4 月 3 日
You can use hold on.
hold on;
That should lock the axes down. If not, use xlim() and ylim() to remember the limits before deletion, then call them again to set the values to the original values after deletion.
RK DISSANAYAKA
RK DISSANAYAKA 2022 年 1 月 7 日
how select two colomns of each matric
Image Analyst
Image Analyst 2022 年 1 月 7 日
@RK DISSANAYAKA I think you commented on the wrong answer or comment. Your question has nothing to do with anything on this page that I can see. But anyway, to get column #9 from a matrix, you can do
oneColumn = yourMatrix(:, 9);
Which you'll learn after taking this short course:

サインインしてコメントする。

Nick
Nick 2011 年 11 月 11 日

0 投票

Are these lines in a figure?
I suppose the easiest way would be to select the lines you dont want with the cursor and hit delete. If you want to do it in your code you could create a seperate handle for each of your line objects and use the delete function.
h(1)=plot(x,y); hold on
h(2)=plot(x,z);
delete(h(2))
Could you be more specific on what your trying to do?

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

タグ

質問済み:

bsd
2011 年 11 月 11 日

コメント済み:

2023 年 1 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by