[英]matlab - graph plottion with unit step function
i want to plot x=(a^n)*u(n)
in matlab. 我想在Matlab中绘制x=(a^n)*u(n)
。 Here is the code: u(n)
here represents the unit step function. 这是代码: u(n)
代表单位步长函数。
clc;
clear all;
close all;
a = input('Enter variable:');
n=[-7:1:7];
for i=1:size(n,2)
if(n(i) > 1)
x(i)=a.^n(i);
else
x(i)=0;
end
end
subplot(2,1,1);
plot(n(i),x(i));
title('function x(n)');
xlabel('n value');
ylabel('x value');
When i execute the code, it is not showing the desired output. 当我执行代码时,它没有显示所需的输出。 Please help. 请帮忙。
It's only plotting one data point: 仅绘制一个数据点:
plot(n(i),x(i));
replace that with 替换为
plot(n,x);
As you can see, this inputs the whole vector n
and x
instead of just the i
th element x(i)
and n(i)
. 如您所见,这将输入整个向量n
和x
而不仅仅是第i
个元素x(i)
和n(i)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.