Finding The x[n^2] Graph
显示 更早的评论
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.
采纳的回答
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.
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.
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.
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
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)

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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
