I am getting an error "index in position 1 exceeds array bounds" in line 25
2 views (last 30 days)
Show older comments
I am attaching the code, in that please make the required changes and attach the modified file so that I can see the desired result. Thank you.
1 Comment
Torsten
on 1 Nov 2024
As you can see, there is no such error in R2024b.
N = 16;
n = 0:N-1;
b = ones(1,N); % Block of ones.
r = n; % Ramp function.
P = 8; % Triangular wave period.
n1 = 0:P/2-1;
n2 = P/2:P-1;
P1 = P*ones(1,length(n2)); A = 1;
tri_block = [2*A*n1/P 2*A*(P1-n2)/P] ;
t = [tri_block tri_block]; % % Periodic Triangular wave
e = (5/6).^n; % One sided exponential.
figure(1)
stem(n,b);
figure(2)
stem(n,r);
figure(3)
stem(n,t);
figure(4)
stem(n,e);
%% i. Create and display r[n-6]*u[n]. figure('Name', 'Tutorial-2. Elementary Signals'); stem(n,r);
grid; hold on;
stem(n+6,r,'r*');
title('r[n] (blue) and v[n]=r[n-6]*u[n] (red)');
%% d. Create and display z[n]=t[n]*(u[n]-u[n-10]).
z = [t(1:10),zeros(1,6)];
figure('Name','Exercise 2.1.3. Elementary Signals');
subplot(3,1,1);
stem(n,t);
grid;
hold on;
stem(n,z,'r*');
title('t[n] (blue) and z[n]=t[n]*(u[n]-u[n-10]) (red)');
Answers (1)
Cris LaPierre
on 1 Nov 2024
Try clearing your workspace before running your script. It looks like you may have created a variable that is taking precedence over the zeros functinon.
zeros=[];
dsp_workspace
0 Comments
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!