i would like to plot a function that outputs 2 plots. One of domain [-2pi,2pi] and other of [-30pi,30pi] with labels and axis
1 次查看(过去 30 天)
显示 更早的评论
hello, i have just started working on matlab and i am stuck with this problem of bieng able to plot 2 functions using fplot and subplot. as per my assignment i am only allowed to use these two. I have written the code as per my understanding and for somereason either my function completes but there are no labels or legends or it doesnt even run, I will show you my code and example of outwhich which i am facing
This is my function
function Output = plot2domains(func, funcType)
figure;
%lets give pie a variable
Pie = pi;
% place your work here
subplot(2,1,1),fplot1 = fplot(func,[-2*Pie,2*Pie]);
xaxis('x'); %we have given our xaxis title here
yaxis('f(x'); %we have given our yaxis title here
%what we have done here is plot the function using FPlot with the interval of -2pi and 2pi
title({[funcType,': f(x) = ',char(func)]; ' for -2\pi < x < 2\pi'});
% add more here
%now we will have another plotting spot in the same function. so
subplot(2,1,2), fplot2 = fplot(func,[-30*Pie,30*Pie]);
xaxis('x');
yaxis('y');
title({[funcType,': f(x) = ',char(func)]; ' for -30\pi < x < 30\pi'});
%you need to make sure to initialize @x in function so that it runs
%properly.
% the below line is just temporary
Output = {fplot1; fplot2};
end
where am i going wrong ?
0 个评论
回答(1 个)
KALYAN ACHARJYA
2021-2-17
编辑:KALYAN ACHARJYA
2021-2-17
For Axes Labels
xaxis replace with xlabel
yaxis replace with ylabel
For legends
refer here
function Output = plot2domains(func, funcType)
subplot(2,1,1),fplot1=fplot(func,[-2*pi,2*pi]);
xlabel('x'); ylabel('f(x');
legend('fplot1');
title({[funcType,': f(x) = ',char(func)]; ' for -2\pi < x < 2\pi'});
subplot(2,1,2),fplot2=fplot(func,[-30*pi,30*pi]);
xlabel('x'); ylabel('y');
legend('fplot2');
title({[funcType,': f(x) = ',char(func)]; ' for -30\pi < x < 30\pi'});
Output = {fplot1; fplot2};
end
Note: Output is cell array with function line
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!