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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
KALYAN ACHARJYA
am 17 Feb. 2021
Bearbeitet: KALYAN ACHARJYA
am 17 Feb. 2021
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
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!