Finding The x[n^2] Graph
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Hello everyone, I need to plot the graph of x[n^2]. When I enter the values like n=n^2 the stem graph has 2 values on the spesific number. For example my code is
n=[-5 -4 -3 -2 -1 0 1 2 3]
x=[1 -2 3 2 1 0 9 7 2]
when I write n=n^2 the -3 and 3, -2 and 2, -1 and 1 values are located on each other. How can I solve this problem? Thanks.
採用された回答
Walter Roberson
2020 年 11 月 14 日
n=[-5 -4 -3 -2 -1 0 1 2 3];
x=[1 -2 3 2 1 0 9 7 2];
stem(x, n.^2)

This is correct output for n^2 vs x, because you have duplicate x values.
stem3(1:length(x), x, n.^2); xlabel('t'); ylabel('x'); zlabel('n^2')

9 件のコメント
enrique128
2020 年 11 月 15 日
編集済み: enrique128
2020 年 11 月 15 日
sir shouldn't it be like stem(n.^2,x) ?
and how can it be possible I mean 3 dimensional graph. It is discrete time signal, I know we have duplicate values but there should be a trick like scaling with n or something like that.
Walter Roberson
2020 年 11 月 15 日
Why would it be stem(n.^2, x) ? the first parameter is to be the independent variable, which is traditionally labeled "x".
Any coordinate that you are doing polynomial scaling on is not an independent variable.
If you intend n.^2 to be your indepedent variable, then draw a mock-up of what you want the outcome to look like.
enrique128
2020 年 11 月 15 日
編集済み: enrique128
2020 年 11 月 15 日
sir can you look this link:
I want to do it like that not a 3 dimensional graph
and also my real signal is stem(n,x) because n is -5 -4 -3 -2 -1 0 1 2 3 that's the reason why I said n must be in the beggining of stem command.
Walter Roberson
2020 年 11 月 15 日
I had to invent new x data because (-5-1)^2 -> 36 and x[36] did not exist
n=[-5 -4 -3 -2 -1 0 1 2 3];
x=[1 -2 3 2 1 0 9 7 2 -10:-1:-37];
stem(n, x((n-1).^2+1)) %the +1 is to move from 0 indexing to 1 indexing

enrique128
2020 年 11 月 15 日
編集済み: enrique128
2020 年 11 月 15 日
sir the link in the algorithm is not like that, for example assume that we have
n=[-3 -2 -1 0 1 2 3 4];
x=[0 0 1 1 1 1 1/2 1/2];
-3^2=9, there is no value at n=9 so there should be 0 in -3.
-2^2=4, there is a value at 4 which is 1/2 so there should be 1/2 in -2.
-1^2=1, there is a value at 1 which is 1 so there should be 1 in -1.
0^2=0, there is a value at 0 which is 1 so there should be 1 in 0.
1^2=1, there is a value at 0 which is 1 so there should be 1 in 1.
2^2=4, there is a value at 4 which is 1/2 so there should be 1/2 in 2.
3^2=9, there is no value at n=9 so there should be 0 in 3.
4^2=16, there is no value at n=16 so there should be 0 in 4.
so my signal become
n=-3 -> 0
n=-2 >1/2
n=-1 > 1
n=0 > 1
n=1 >1
n=2 >1/2
n=3 -> 0
n=4 -> 0
The algorithm is like that.
Walter Roberson
2020 年 11 月 15 日
n = [-3 -2 -1 0 1 2 3 4];
x = [0 0 1 1 1 1 1/2 1/2];
t = n.^2;
mask = t >= 1 & t <= length(x) & fix(t) == t;
y = zeros(size(t));
y(mask) = x(t(mask));
stem(n, y)

enrique128
2020 年 11 月 15 日
編集済み: enrique128
2020 年 11 月 15 日
sir the values that i write is not the same as your graph it should be like 0 1/2 1 1 1 1/2 0 0. The time interval is true but the values are wrong
Walter Roberson
2020 年 11 月 15 日
n = [-3 -2 -1 0 1 2 3 4];
x = [0 0 1 1 1 1 1/2 1/2];
y = interp1(n, x, n.^2, 'linear', 0);
stem(n, y)

enrique128
2020 年 11 月 15 日
you are a hero! thanks sir.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
製品
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
