Plot for different conditions of function
이전 댓글 표시
Hi everyone,
i have the task that I have to make plot for different conditions y(x) for different value x.
The following code I have is below. If is correct.
But plot did not work. I thought that missing hold on or something like that but also did not work.
clear all
close all
clc
x=rand
if x<6
y=2;
% fprintf ('%.2f, %d\n',x,y)
elseif x>=6 & x<20
y=x-4;
% fprintf ('%.2f, %.2f\n',x,y)
elseif x>=20
y=36-x;
% fprintf ('%.2f, %.2f\n',x,y)
end
fprintf ('%.2f, %.2f\n',x,y)
for x=-30:1:30
if x<6
y1=2;
plot(x,y1)
elseif x>=6 & x<20
y2=x-4;
plot(x,y2)
elseif x>=20
y3=36-x;
plot(x,y3)
end
end
Thank you!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!