Hi all,
I have a .fig file that is made up of red and black lines and I want to be able to export this as .pdf. Plot twist: Each of the red lines shown here has an underlying black line that I want to just get rid of, so it results in only purely-black and purely-red lines. Any idea how to solve this?
Thanks!

댓글 수: 1

darova
darova 2019년 8월 19일
Do you have a source where those curves come from? A script?

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

 채택된 답변

Chris
Chris 2019년 8월 19일

0 개 추천

.fig files retain Children information of the figure; you can loop over the Children and delete based on color.

댓글 수: 5

Hans Sunaryanto
Hans Sunaryanto 2019년 8월 19일
I've tried everything I can think of using this approach but I can't seem to get it to delete the black lines overlapping the red. Can you give me a suggestion on how to approach this?
Thanks a bunch!
Chris
Chris 2019년 8월 19일
편집: Chris 2019년 8월 19일
hf = figure(1); clf, hold on
%% Make a two color plot
for ii = 1:20
vX = [rand, rand];
vY = [rand, rand];
if (rand > 0.5)
plot(vX, vY, 'r')
else
plot(vX, vY, 'k')
end
end
%% remove black things
curAxes = get(hf, 'Children');
for curChild = get(curAxes, 'Children')'
if (isequal(curChild.Color, [0 0 0])) % black lines
delete(curChild)
end
end
Also check that you are looking ato two things - ie the red and black are different lines. There are multiple color properties with some plotted things; 'color', 'MarkerEdgeColor' ,'MarkerFaceColor' make sure the line you are looking at is not two colors simultaneously.
darova
darova 2019년 8월 21일
Chris, is it answers your question?
Hans Sunaryanto
Hans Sunaryanto 2019년 8월 22일
Hi Chris,
The function you gave me would delete all of the black lines I have in my figure. This isn't exactly what I was looking for, since I want to only delete the black lines that are precisely located under the red ones. Do you have any idea how we can incorporate this function (or another function) to solve it?
Thanks!
Chris
Chris 2019년 8월 23일
You will need to then loop over all combinations of red and black lines testing for pairs.
The pair test: If the end points of the overlapping lines are coincident you can do a distance test on each end. Else you can try using polyfit to determine if the two lines have the same slope and y-intercept.
Or if you have a small number of plots and lines you can loop over each black line, make the line a new color and used input() to specify if that line should be deleted; if not restore its color

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2019년 8월 19일

댓글:

2019년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by