PradeepBhati
PradeepBhati

Reputation: 73

matlab - graph plottion with unit step function

i want to plot x=(a^n)*u(n) in matlab. Here is the code: u(n) here represents the unit step function.

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.

Upvotes: 0

Views: 5286

Answers (1)

Gunther Struyf
Gunther Struyf

Reputation: 11168

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 ith element x(i) and n(i).

Upvotes: 3

Related Questions