I can't figure out why am not getting a plot on my code

조회 수: 1 (최근 30일)
John
John 2022년 10월 25일
답변: Chunru 2022년 10월 25일
Write a MATLAB code for plot original and transformation function of
function y=ga(t);
y = -2*(t<=-1)+2*t.*(-1<t&t<=1)+(3-t.^2).*(1<t&t<=3)-6*(t>3);
figure;
tmin=-3;tmax=8;N=100;
dt=(tmax-tmin)/N; t=tmin+dt*[0:N]';
g0=ga(t);g1=-3*ga(4-t);
subplot(2,1,1);p=plot(t,g0,'k');set(p,'LineWidth',2);grid;
ylabel('g(t)');
title('(a)-g(t)=-2,t<-1,2t,-13')
subplot(2,1,2);p=plot(t,g1,'k');set(p,'LineWidth',2);grid;
xlabel('t');ylabel('-3g(4-t');

답변 (1개)

Chunru
Chunru 2022년 10월 25일
If you put the script and local function ga in the same file, then local functions should be placed at the end of the files as shown below. You can also put the local function in a separate file,
figure;
tmin=-3;tmax=8;N=100;
dt=(tmax-tmin)/N; t=tmin+dt*[0:N]';
g0=ga(t);g1=-3*ga(4-t);
subplot(2,1,1);p=plot(t,g0,'k');set(p,'LineWidth',2);grid;
ylabel('g(t)');
title('(a)-g(t)=-2,t<-1,2t,-13')
subplot(2,1,2);p=plot(t,g1,'k');set(p,'LineWidth',2);grid;
xlabel('t');ylabel('-3g(4-t');
function y=ga(t);
y = -2*(t<=-1)+2*t.*(-1<t&t<=1)+(3-t.^2).*(1<t&t<=3)-6*(t>3);
end

카테고리

Help CenterFile Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by