I am getting an error "index in position 1 exceeds array bounds" in line 25

26 次查看(过去 30 天)
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 个评论
Torsten
Torsten 2024-11-1,15:50
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)');

请先登录,再进行评论。

回答(1 个)

Cris LaPierre
Cris LaPierre 2024-11-1,18:25
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
Index in position 1 exceeds array bounds.

Error in dsp_workspace (line 25)
z = [t(1:10),zeros(1,6)];

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by