凡例の系列名に変数の値を入れたいです

48 views (last 30 days)
sota kagawa
sota kagawa on 24 Jun 2020
Commented: sota kagawa on 24 Jun 2020
凡例に変数のなかの値をいれたいです。方法があれば教えて欲しいです。
open_system( 'MPC_SISO_0_block' )
mpc_out = sim( 'MPC_SISO_0_block' );
figure
title( 'Deterioration of the MPC' )
hold on
plot( mpc_out.ScopeData{1}.Values.Time,mpc_out.ScopeData{2}.Values.Data,'LineWidth',2 )
dm = 0.1;
for cnt = -3:3
dp = dm * cnt;
d_K0 = K0 * dp;
num_p = K0 + d_K0;
plant = tf( num_p, den_p );
open_system( 'MPC_SISO_0_block' )
mpc_out = sim( 'MPC_SISO_0_block' );
plot( mpc_out.ScopeData{1}.Values.Time,mpc_out.ScopeData{2}.Values.Data )
% plot( mpc_out.ScopeData{1}.Values.Time,mpc_out.ScopeData{2}.Values.Data*(1+cnt*0.1) )
end
legend
title( 'MPC K' )
hold off
 これはスクリプトの一部ですが、このd_K0の値を凡例に入れ、例えばd_K0=1のとき、K=1と表示されるようにしたいです。

Accepted Answer

Takumi
Takumi on 24 Jun 2020
以下のようにしてDisplayNameを設定するのはいかがでしょうか.
open_system( 'MPC_SISO_0_block' )
mpc_out = sim( 'MPC_SISO_0_block' );
figure
title( 'Deterioration of the MPC' )
hold on
plot( mpc_out.ScopeData{1}.Values.Time,mpc_out.ScopeData{2}.Values.Data,'LineWidth',2 )
dm = 0.1;
for cnt = -3:3
dp = dm * cnt;
d_K0 = K0 * dp;
num_p = K0 + d_K0;
plant = tf( num_p, den_p );
open_system( 'MPC_SISO_0_block' )
mpc_out = sim( 'MPC_SISO_0_block' );
txt = ['K=',num2str(d_K0)];
plot( mpc_out.ScopeData{1}.Values.Time,mpc_out.ScopeData{2}.Values.Data ,'DisplayName',txt)
% plot( mpc_out.ScopeData{1}.Values.Time,mpc_out.ScopeData{2}.Values.Data*(1+cnt*0.1) )
end
legend show
title( 'MPC K' )
hold off
  1 Comment
sota kagawa
sota kagawa on 24 Jun 2020
実行したところうまく動きました。本当にありがとうございます。

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!