I am getting an error "index in position 1 exceeds array bounds" in line 25
27 ビュー (過去 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
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
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Sources についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!