2012-04-18 68 views
0
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

要創建包含數值標題字符串,請使用num2str

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