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

3 次查看(过去 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 ?

回答(1 个)

KALYAN ACHARJYA
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
  1 个评论
Fahad Qazi
Fahad Qazi 2021-2-17
Thank you. i wanted to ask why was xaxis not working in the function ? also since i am passing a funcType which is basically a variable that holds the function algorithm how can i not show the @(x) function in the function. A clear example will be with of a picture here it is.
i want to remove here for instance @(x)24*x but if i do it directly, my function becomes null and doesnt work when it is passed by value into the function

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by