0

not sure its the right place to write this here or not,but i'll try my luck.
been given an example of plotting a graph,writing this into the command prompt :

L = 31;
nn = 0:(L-1);
imp = zeros(L,1);
imp(1) = 1;
stem(nn,imp)

this gives a graphic display.

then i have a few examples to do, the first being x [n]= 0.9∂[n-5] range being 1≤n≤20
could anyone giving a hand,using the example format, then il have a rough idea of trying the others.thanks

2
Contributors
3
Replies
9
Views
5 Years
Discussion Span
Last Post by Taywin
0

You may read one of matlab tutorials here or this official site. The given code is to generate a horizontal array (dimension 1xL) value from 0 up to L-1, and then store it in variable nn. Then create an vertical array size of Lx1 filled with all 0 except the first index (if I remember correctly, matlab use 1-index instead of 0-index). Then you plot it.

I am not sure about the symbol in your equation, so can't really say much. What I am thinking is that use your n as horizontal array, compute each n to find out x[n] and put it in a vertical array. Then you plot it.

L = 20;
nn = 1:L;        # create array [1, ..., L]
x = zeros(L,1);  # create vertical array size of Lx1
for n = 1:L    # loop through n value to compute for x[n]
  x(n) = equation_blah_blah;
end
stem(nn,x);      # plot it

PS: I believe there is a better way to utilize Matlab's efficiency of array computation (parallel computation). I can't remember the syntax though.

Edited by Taywin

0

well in my examples, its for an absolute beginner like myself,only starting off here. whats the imp? impulse or something like that?

0

No, they are all variable names. When you declare a vairable in Matlab, you simply start with a name and assign a value to it. I don't know how much programming concept you have. A Computer language is just a language with different syntax. If you get passed the syntax, everything is simple to understand.

L = 31;
# The above line means you declare a variable L and assign value 20 to it

nn = 0:(L-1);
# The above line means you declare a vairable nn and create a horizontal array
# containing values from 0 up to L-1 which is 30 [0, 1, ..., 30]

imp = zeros(L,1);
# The above line means you declare a variable imp, and then assign a vertical
array size of Lx1 (31x1) filled with value 0 in it.

imp(1) = 1;
# The above line means you assign value 1 to the first index of the variable.
# Matlab array index starts from 1, not 0.

stem(nn,imp)
# The above line is calling a function stem to plot a graph using
# nn variable values on the x-axis and imp variable values on the y-axis

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.