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 view (last 30 days)
Show older comments
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);
title('Analytical System Response y(t)');
xlabel('time (s)');
ylabel('amplitude');
3 Comments
John D'Errico
on 7 Feb 2024
Edited: John D'Errico
on 7 Feb 2024
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.
Answers (2)
Walter Roberson
on 7 Feb 2024
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.
0 Comments
See Also
Categories
Find more on Subplots 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!