2017-04-12 1 views
1

関数y [n] = x [n + 2]をプロットします。私の問題は、それが正しい範囲でプロットしていないか、ゼロのサンプルポイントを描画していないことです。右のプロットを取得するには、変数nまたはXを変更する方法matlabに離散信号をプロットする方法は?

enter image description here

enter image description here

n = 1:6; 
x = 1:1:8; 

f = figure; 
subplot(1,2,1)  
stem(n, x(n)); 
axis([-3,8, 0, 7]); 
xlabel('n'); 
ylabel('x[n]'); 
title('Subplot 1') 

subplot(1,2,2)  
stem(n, x(n + 2));  
xlabel('n'); 
ylabel('y[n]'); 
title('Subplot 2') 

?最後に は、それは次のようになりべき:

enter image description here

+0

に変換を適用することができますか?関数y = x(n + 2) – Suever

+0

@Sueverとまったく同じように見えますが、質問を編集しました。 x(n)は0から6に限定されています。 – j35t3r

答えて

1

あなたの従属変数とインデックスの概念を混乱されています。あなたは、あなたがこの機能を評価するn値の範囲を渡す必要がありますあなたは

function y = x(n) 
    % Set all outputs to 0 
    y = zeros(size(n)); 

    % Replace the values that fall between 0 and 6 with their same value 
    y(n >= 0 & n <= 6) = n(n >= 0 & n <= 6); 
end 

を知っている関係を使用して入力nを変換機能xを構築する必要があります。

nvalues = -3:8; 
yvalues = x(nvalues); 

stem(nvalues, yvalues) 

また、それと間違って何n

nvalues = -3:8; 
yvalues = x(nvalues + 2); 

stem(nvalues, yvalues) 
+0

このエラーが発生します:代入A(I)= Bでは、BとIの要素の数は同じでなければなりません。 xのエラー(行6) y(n> = 0&n <= 6)= n; – j35t3r

+0

@ j35t3r – Suever

+0

あなたの努力に感謝します – j35t3r

関連する問題