Plotting after a for loop
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
I'm having trouble plotting the graph in the picture. I've been trying with and without the for loop in the code but i have no idea what i'm doing wrong. please help :(

for x =[-5:5];
if x < 0 ;
y = 0
else if x >= 0 ;
y = 0.5
end
end
end
plot(x,y)
hold on
댓글 수: 0
답변 (1개)
KSSV
2020년 8월 11일
x = -5:5 ;
y = zeros(size(x)) ;
y(x>=0.5) = 0.5 ;
plot(x,y)
댓글 수: 2
Lukas Arkenklo
2020년 8월 11일
KSSV
2020년 8월 11일
You should refine x.
x = linspace(-5,5,1000) ;
y = zeros(size(x)) ;
y(x>=0.5) = 0.5 ;
plot(x,y)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!