필터 지우기
필터 지우기

Why doesn't it work ? Please help

조회 수: 2 (최근 30일)
David
David 2023년 3월 16일
편집: VBBV 2023년 3월 16일
Hey!
I need to write this function , but i have tried it and it doesn't work.
Where am I wrong ?
  댓글 수: 2
Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 3월 16일
The if function does not work like that.
You should try something like:
dt=0.01;
t=4;
T=0:dt:t;
p=zeros(size(T));
for i=1:length(T)
if T(i)>0 & T(i)<t/4
p(i)=sin(pi*T(i));
elseif T(i)>t/2 & T(i)<3*t/4
p(i)=1;
end
end
plot(T,p)
David
David 2023년 3월 16일
Thank you !
I will try

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

답변 (1개)

KSSV
KSSV 2023년 3월 16일
dt = 0.01;
t = 4;
T = 0:dt:t;
% First Quarter
r1 = 0:dt:t/4 ;
p1 = sin(pi.*r1) ;
plot (r1,p1)
% Define second Quarter here and append it to the above
  댓글 수: 2
David
David 2023년 3월 16일
Hey !
I tried this and the second quarter didn't work
clear
close all
clc
dt = 0.01;
t = 4;
T = 0:dt:t;
% First Quarter
r1 = 0:dt:t/4 ;
p1 = sin(pi.*r1) ;
figure(1)
plot (r1,p1)
hold on
% Second Quarter
r2 = t/4:dt:t/2
p2 = 0;
y = [r2 , p2]
figure(2)
plot(y)
hold off
VBBV
VBBV 2023년 3월 16일
편집: VBBV 2023년 3월 16일
% Second Quarter
r2 = t/4:dt:t/2
p2 = zeros(size(r2));
y = [p1 , p2]
figure(2)
plot([r1 r2],y)
Try it as above

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by