# How to plot This graph in matlab?

3 views (last 30 days)
Itqan Ismail on 1 Feb 2023
Commented: DGM on 1 Feb 2023
x=[1.0:0.1:3.0];
%Composition
y=-2.03^9-3*x^2)+5.76^(-3x)+1;
z=-1.11^-2*x^2+6.49^-2*x+9.99;
plot(x,y,'-b',x,z,'-r')
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend('a) FFA','b)TAG');

DGM on 1 Feb 2023
Edited: DGM on 1 Feb 2023
1.00E-2 is shorthand for scientific notation 1.00*10^-2.
% define x
x = 1.0:0.05:3.0;
% YData as row vectors in a matrix
y = zeros(3,numel(x)); % preallocate
y(1,:) = -2.03E-3*x.^2 + 5.76E-3*x + 1E2;
y(2,:) = -1.11E-2*x.^2 + 6.49E-2*x + 9.99E1;
y(3,:) = -2.73E-2*x.^3 + 1.05E-1*x.^2 - 1.42E-1*x + 1E2;
% plot all y vs x
hp = plot(x,y);
% set colors using short names or direct tuples
% set line and marker styles as needed
linecolors = {'k',[0.8 0.5 0],[0.8 0.8 0]};
for k = 1:3
hp(k).Color = linecolors{k};
hp(k).Marker = 'o';
hp(k).MarkerFaceColor = linecolors{k};
hp(k).MarkerSize = 3;
end
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend(hp,{'a) FFA','b) TAG','c) something'});
If you want to add equations to the plot, you can use annotation()
Why aren't the curves in the same location? The equations in the annotations contain constants which are rounded. It's also likely that the curves are measured data and the equations are a polynomial fit, so they might not actually be identical.
DGM on 1 Feb 2023
... or if we assume the plotted data are measured values and not the polynomial fit, we could approximate the measured values instead of trying to refine the fit.
% define x
x = 1.0:0.05:3.0;
% YData as row vectors in a matrix
% plot all y vs x
hp = plot(x,S.y);
% set colors using short names or direct tuples
% set line and marker styles as needed
linecolors = {'k',[0.8 0.5 0],[0.8 0.8 0]};
for k = 1:3
hp(k).Color = linecolors{k};
hp(k).Marker = 'o';
hp(k).MarkerFaceColor = linecolors{k};
hp(k).MarkerSize = 3;
end
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend(hp,{'a) FFA','b) TAG','c) something'});
Note that this is a better approximation of what the image itself shows.

KSSV on 1 Feb 2023
I have shown one plot for you reference. You may extend the same to others.
x=1.0:0.1:3.0;
y=-2.03*10^-3*x.^2+5.76*10^-3*x+1*10^2 ;
plot(x,y,'-b')
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend('a) FFA');
Itqan Ismail on 1 Feb 2023

### Categories

Find more on Graphics Performance in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by