轴循环内不同值的标题

时间:2012-04-18 03:57:52

标签: matlab matlab-figure

q=[1, 4, 10, 50, 100];
for j=1:length(q)
    for i=1:q(j)
        Dq=D(1:q(j),1:q(j));
        Vq=V(1:q(j),1:q(j));
        Cq=C(1:q(j));
        Bq=B(1:q(j));
    end
    S = logspace(-8,4,500);
    k=1;
    for p=S
        Y(k)=Cq*Vq*inv(1i*p*eye(q(j))-Dq)*inv(Vq)*Bq;
        k=k+1;
    end
    figure;
    hold on

    subplot(2,1,1);
    semilogx(S,real(Y));
    grid; ylabel('|H(j\omega)|'); 
    title(['Bode Plot: Magnitude Response (Real)q=',q(j)]);

    subplot(2,1,2);
    semilogx(S,imag(Y));
    grid; xlabel('\omega (rad/sec)'); ylabel('\angleH(j\omega)'); 
    title(['Bode Plot: Phase Response (Imaginary) q = ',q(j)]);
end

我想在标题中打印q的值,例如q=1,... q=100。代码工作正常但它没有在标题中显示q的值,特别是我正在绘制的q的值。如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

要为包含数字值的标题创建字符串,请使用num2str

title(['Bode Plot: Phase Response (Imaginary) q = ' num2str(q(j))]);