how to use for loop to plot these 3 functions, the increment for the axis is 0.1 as shown
x1=0:0.1:3; %first range
x2=3:0.1:6; %second range
x3=6:0.1:8; %third range
f1= @(x1) cos(x1); %first function
f2= @(x2) exp(-0.4*x2); %second function
f3= @(x3) 2*cos(x3); %third function
plot(x1,f1(x1),x2,f2(x2),x3,f3(x3))
grid
title('Function F(x)');
xlabel('ranges');
ylabel('Functions');
legend

답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 2월 1일

0 개 추천

hello
mu suggestion below :
for ci = 1:3 % nb of functions to be displayed
if ci == 1
x=0:0.1:3; %first range
y = cos(x); %first function
elseif ci == 2
x=3:0.1:6; %second range
y = exp(-0.4*x); %second function
elseif ci == 3
x = 6:0.1:8; %third range
y = 2*cos(x); %third function
end
plot(x,y)
hold on
grid on
title('Function F(x)');
xlabel('ranges');
ylabel('Functions');
legend
end
hold off

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2021년 1월 31일

답변:

2021년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by