MATLAB Answers

# Plotting sequences over intervals

조회 수: 18(최근 30일)
Connor Wright 2020년 11월 13일
댓글: Jon 2020년 11월 20일
Hello,
How would I go about plotting a seqeunce over the below intervals?
A) 𝑥(𝑛) = 2𝛿(𝑛 + 1)− 𝛿(𝑛 −6), −10 ≤ 𝑛 ≤ 10.
B) 𝑥(𝑛) = {… , 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, … }; −20 ≤ 𝑛 ≤ 12.
Thanks
##### 댓글 수: 6표시숨기기 이전 댓글 수: 5
Jon 2020년 11월 19일
I define it as a helper function in my script above

댓글을 달려면 로그인하십시오.

### 채택된 답변

Jon 2020년 11월 19일
You could do it like this
n = -10:10
x = zeros(length(n),1) % preallocate array of zeros to hold result
for k = 1:length(n)
% evaluate x(n)
x(k) = 2*usmpl(n(k)+ 1) - usmpl(n(k)-6);
end
% plot result
stem(n,x)
% define helper function
function delta = usmpl(n)
% define unit sample function
if n == 1
delta = 1
else
delta = 0
end
end
##### 댓글 수: 6표시숨기기 이전 댓글 수: 5
Jon 2020년 11월 20일
Great that your working on developing your skills, sounds like you have lots of talents, definitely post some new questions if you have more MATLAB questions. I've learned a lot from this site, there are a lot of knowledgeable people answering questions. By the way, you may already be beyond this, but if not the MATLAB On Ramp course is good for getting a quick start https://www.mathworks.com/learn/tutorials/matlab-onramp.html

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

SaiDileep Kola 2020년 11월 16일
Hi Connor,
Start by copying complete code provided by Jon and usmpl is just a local function created to use. Don't use usmpl in the terminal without defining, that will solve your issue.
##### 댓글 수: 7표시숨기기 이전 댓글 수: 6
Jon 2020년 11월 19일
Oops now I feel kind of silly, didn't realize I had just continued my original comment. I will try to copy and paste into an answer.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!