Why doesn't it work ? Please help
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey!
I need to write this function , but i have tried it and it doesn't work.
Where am I wrong ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1326065/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1326070/image.jpeg)
2 Kommentare
Antoni Garcia-Herreros
am 16 Mär. 2023
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)
Antworten (1)
KSSV
am 16 Mär. 2023
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
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!