figure adding plot to named figures?

조회 수: 91 (최근 30일)
franco otaola
franco otaola 2020년 4월 3일
댓글: Rik 2020년 4월 3일
hello,
how can i add other data to different existing figures (plots) when they are multiples figures open.
i mean for example:
figure(1)
plot(x,y)
figure(2)
plot(t,z)
if condition=true
figure(1)
plot(x2,y2)
figure(2)
plot(t2,z2)
end
and keep the x,y and t,z in the respective figures, i know that i could do plot(x,y,x2,y2) and respectly plot(t,z,t2,z2) but i would like to know if there is a way to do it in the way i presented before, as the data is calculated with conditionals so there is the posibility that x2,y2 and t2,z2 will not exist (if the condition is not satified giving error to plot(x,y,x2,y2)) and i not looking to define all the possible variables with NaN in the begining of the code.
thanks!

채택된 답변

Rik
Rik 2020년 4월 3일
You can modify the NextPlot property of your axes objects. You can do this by modifying the property, or by using hold on.
h=struct;%create struct to hold all handles
h(1).f=figure(1);clf(h(1).f)%create blank figure
h(2).f=figure(2);clf(h(2).f)
h(1).ax=axes('Parent',h(1).f,'NextPlot','add');%create axes
h(2).ax=axes('Parent',h(2).f,'NextPlot','add');
plot(x,y,'Parent',h(1).ax)
plot(t,z,'Parent',h(2).ax)
if condition
plot(x2,y2,'Parent',h(1).ax)
plot(t2,z2,'Parent',h(2).ax)
end
  댓글 수: 2
franco otaola
franco otaola 2020년 4월 3일
hello, thanks for your answer,
could you explan me what is the function of 'Parent' part? or where to find it in the help ? as in the plot help i have not find this option,
thanks a lot
Rik
Rik 2020년 4월 3일
The Parent property describes what object should contain the object you are about to create. I prefer to use the Name,Value syntax for this to make it explicit, even for functions like plot that allow you to set the parent in the normal parameters.
As the doc for plot describes: "plot(_,Name,Value) specifies line properties using one or more Name,Value pair arguments. For a list of properties, see Line Properties."

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by