Adding legend to multiple figures

조회 수: 18 (최근 30일)
Tyler Robertson
Tyler Robertson 2017년 3월 25일
답변: Star Strider 2017년 3월 25일
I am trying to have 2 figures with legends. The legend only prints to figure(2), and no legend shows up on figure(1). Cannot find information for this issue.
%Magnitude Plot
figure(1)
opts = bodeoptions;
opts.FreqUnits = 'Hz';
opts.Xlim = [100,100000]; % x-axis limits
opts.Ylim = [-100,100]; % y-axis limits
opts.PhaseVisible = 'off'; % Turn off phase plot
bodeplot(Gp,opts); % Bode plot of Gp
hold on
T = Gc*Gp; % Loop Transfer Function (T)
bodeplot(T,opts); % Bode plot of Gc*Gp
title('Magnitude Plot of Plant & Loop Transfer Function');
legend('Plant','Loop Transfer Function')
%Phase Plot
figure(2)
opts = bodeoptions;
opts.FreqUnits = 'Hz';
opts.Xlim = [100,100000]; % x-axis limits
opts.Ylim = [-360,360]; % y-axis limits
opts.MagVisible = 'off'; % Turn off magnitude plot
bodeplot(Gp,opts); % Bode plot of Gp
hold on
T = Gc*Gp; % Loop Transfer Function (T)
bodeplot(T,opts); % Bode plot of Gc*Gp
title('Phase Plot of Plant & Loop Transfer Function');
legend('Plant','Loop Transfer Function')

답변 (1개)

Star Strider
Star Strider 2017년 3월 25일
The Control System Toolbox bode and bodeplot functions don’t work like other plots.
When I want to create special plots of transfer functions, I ask for 3 outputs from the bode function, then plot the data as regular subplot plots. I can do anything I with them that I would do with any other plot then. They don’t look any different from the plots that bode or bodeplot produce, so you don’t lose anything.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by