필터 지우기
필터 지우기

Hello. Im currently creating a code in Matlab and I am running into this error that I will attach in a screenshot. I am new to Matlab so I am having trouble fixing it.

조회 수: 1 (최근 30일)
clear all
clc
t=0:0.01:5;
h=12.0 * exp(-2.0*t).*(t>= 0);
x=5* (t >= 0)-5* (t >=1.0);
y=conv(x,h,'full')*0.01;
figure;
subplot(3,1,1);
plot(t,h,'r','Linewidth',2);
title('Impulse Response h(t)');
xlabel('time (s)');
ylabel('amplitude');
subplot(3,1,2);
plot(t,x,'b','Linewidth',2);
title('input signal x(t)');
xlabel('time (s)');
ylabel('amplitude');
subplot(3,1,3);
plot(t(1:length(y)),y,'g','Linewidth',2);
Index exceeds the number of array elements. Index must not exceed 501.
title('Analytical System Response y(t)');
xlabel('time (s)');
ylabel('amplitude');
  댓글 수: 3
John D'Errico
John D'Errico 2024년 2월 7일
편집: John D'Errico 2024년 2월 7일
When you attach a picture of code, you make it far more difficult for someone to help you, since we are forced to retype your code completely.
What is worse, if you don't even show the error you got! Can we read your mind? I'm tryign, but the MATLAB crystal ball is foggy today.
Is there a good reason why you want to make it more difficult to get help, since it is trivial to paste in the text itself?
When you do give us the text, also paste in the COMPLETE ERROR MESSAGE. So EVERYTHING in red.
Logan
Logan 2024년 2월 7일
here is the code that is in the screenshot. Im sorry, this is the first question I have asked and did not know the exact specifics on how to post. The error that I am getting is "Index exceeds the number of array elements. Index must not exceed 501."
clear all
clc
t=0:0.01:5;
h=12.0 * exp(-2.0*t).*(t>= 0);
x=5* (t >= 0)-5* (t >=1.0);
y=conv(x,h,'full')*0.01;
figure;
subplot(3,1,1);
plot(t,h,'r','Linewidth',2);
title('Impulse Response h(t)');
xlabel('time (s)');
ylabel('amplitude');
subplot(3,1,2);
plot(t,x,'b','Linewidth',2);
title('input signal x(t)');
xlabel('time (s)');
ylabel('amplitude');
subplot(3,1,3);
plot(t(1:length(y)),y,'g','Linewidth',2);
Index exceeds the number of array elements. Index must not exceed 501.
title('Analytical System Response y(t)');
xlabel('time (s)');
ylabel('amplitude');

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

답변 (2개)

Walter Roberson
Walter Roberson 2024년 2월 7일
y=conv(x,h,'full')*0.01;
The length of a 'full' convolution is longer than than the individual inputs: it is (length(First) + length(Second) - 1)
plot(t(1:length(y)),y,'g','Linewidth',2);
You use the length of the full convolution to index something that is the length of the original signal.

Image Analyst
Image Analyst 2024년 2월 7일
If you want to clip off the ends, use the 'same' option instead of 'full' in conv.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by