Storing plots as a variable in a for loop
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
The context to this code is; it is plotting 3 graphs and the data from these graphs need to be combined onto a four graph. So whilst I am processing the data for the first three graphs, I want to plot the relevant graph section for the fourth graph and store it in an array so that I can then call it for the fourth graph and its the legend without having to cycle through the data again.
r_col=[5,8,11]
h_col=[6,9,12]
size=[18,21,25]
xD=[2,6,10]
for z=1:3
    clf
    hold on
    grid on
    r=data(1:size(z),r_col(z))
    h=data(1:size(z),h_col(z))
    v=4*sqrt(h*sin(alpha))
    A(z)=plot(5*v+xD(z)*D,r);
    plot(r,v)
    scatter(r,v)
    name=[int2str(xD(z)),'D Velocity Profile']
    xlabel('Distance from centre line (mm) ');
    ylabel('Velocity of jet (m/s)');
    print(name,'-dpng','-r300');
end    
and then later on when I am doing the legend for the fourth graph, I would like to call it like so:
%applies axis labels
legend([L1,A(1),A(2),A(3),L6,L8,L9],'Core','2D velocities','6D velocities','10D velocities','Nozzle and Origin','Centre Line','Divergence Lines','FontSize',6,'Location','northwest')
So the key issue here is how to store plots so they can be used later?
댓글 수: 8
  Tommy
      
 2020년 4월 15일
				Note that the Visible property is not the same as the HandleVisibility property. clf and findobj care about the latter, not the former:
>> a = axes;
>> clf
>> a
a = 
  handle to deleted Axes
versus
>> a = axes;
>> a.HandleVisibility = 'off';
>> clf
>> a
a = 
  Axes with properties:
             XLim: [0 1]
             YLim: [0 1]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'
  Show all properties
and
>> A = plot(1:10, 'HandleVisibility', 'off');
>> findobj('type','line')
ans = 
  0×0 empty GraphicsPlaceholder array.
>> A.HandleVisibility = 'on';
>> findobj('type','line')
ans = 
  Line with properties:
              Color: [0 0.4470 0.7410]
          LineStyle: '-'
          LineWidth: 0.5000
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [1 2 3 4 5 6 7 8 9 10]
              YData: [1 2 3 4 5 6 7 8 9 10]
              ZData: [1×0 double]
  Show all properties
답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


