I have a bug on my code
์ด์ ๋๊ธ ํ์
It keeps saying u(t) is not defined even though I did.
% t bounded between -1 and 1 with a step of 0.01
t = -1:0.01:1;
%Plot on a graph
x_1 = 5 * u(t-0.1);
x_2 = 2 * rectangularPulse(t/0.3);
x_3 = 4 * sinc(t/0.2);
figure
plot(t,x1,'g',t,x2fx,'b',t,x3,'c');
% Label the graph
xlabel('Amplitude')
ylabel('Time t[s]')
title('Assignment 3')
legend("x1(t)","x2(t)","x3(t)");
grid on;
% Step function implementing ๐ฆ(๐ก) = ๐ข(๐ก)
function y =u(t)
y(t > 0) = 1;
y(t == 0) = 0.5;
y(t < 0) = 0;
end
% Rectangular pulse function implementing ๐ฆ(๐ก) = ฮ (๐ก)
function y = rectangularPulse(t)
y = (t >= -0.5 & t <= 0.5);
end
% Sinc function implementing ๐ฆ(๐ก) = ๐ ๐๐๐(๐ก)
function y = sinc(t)
y = (sin(pi.*t) / pi.*t);
end
๋๊ธ ์: 1
Stephen23
2025๋
9์ 14์ผ
์ด๋: Image Analyst
2025๋
9์ 14์ผ
You have not defined the following variables/functions: x1, x2fx, x3.
Once you define those variables then your code works:
% t bounded between -1 and 1 with a step of 0.01
t = -1:0.01:1;
%Plot on a graph
x1 = 5 * u(t-0.1); % fixed name
x2 = 2 * rectangularPulse(t/0.3); % fixed name
x3 = 4 * sinc(t/0.2); % fixed name
figure
plot(t,x1,'g',t,x2,'b',t,x3,'c');
% Label the graph
xlabel('Amplitude')
ylabel('Time t[s]')
title('Assignment 3')
legend("x1(t)","x2(t)","x3(t)");
grid on;
% Step function implementing ๐ฆ(๐ก) = ๐ข(๐ก)
function y = u(t)
y(t > 0) = 1;
y(t == 0) = 0.5;
y(t < 0) = 0;
end
% Rectangular pulse function implementing ๐ฆ(๐ก) = ฮ (๐ก)
function y = rectangularPulse(t)
y = (t >= -0.5 & t <= 0.5);
end
% Sinc function implementing ๐ฆ(๐ก) = ๐ ๐๐๐(๐ก)
function y = sinc(t)
y = (sin(pi.*t) / pi.*t);
end
๋ต๋ณ (1๊ฐ)
Image Analyst
2025๋
9์ 14์ผ
0 ๊ฐ ์ถ์ฒ
You have not defined x1. x1 is a differently-named variable than x_1.
- If they should be the same variable, then use a consistent name, either with or without the underline.
- Otherwise if they are different variables you need to define exactly what x1 is.
์นดํ ๊ณ ๋ฆฌ
๋์๋ง ์ผํฐ ๋ฐ File Exchange์์ Animation์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
