How to plot two different curves on same axes?

3 vues (au cours des 30 derniers jours)
PAWAN KUMAR YADAV
PAWAN KUMAR YADAV le 1 Mai 2015
I have to plot for COD vs TIME. I have discrete values of COD against time and also expression for relationship between COD and TIME. I can plot both the cases differently.
So, how can I merge the two curves of COD and TIME on same axes?

Réponses (3)

Joseph Cheng
Joseph Cheng le 1 Mai 2015
Yes you can, read the documentation on plot(). There should be sufficient examples showing how to plot plenty of items on one axes.

Azzi Abdelmalek
Azzi Abdelmalek le 1 Mai 2015
plotyy(t,x1,t,x2)

Star Strider
Star Strider le 1 Mai 2015
Modifié(e) : Star Strider le 1 Mai 2015
This will do what you want. Adapt it as needed:
TIME = linspace(0, 10, 20);
COD = randi(10, 1, length(TIME));
xmtx = [ones(length(TIME),1) TIME'];
B = xmtx\COD'; % Linear Regression: COD - TIME
COD_fit = xmtx*B; % Fitted Line
figure(1)
plot(TIME, COD, 'bp')
hold on
plot(TIME, COD_fit, '-r')
hold off
grid
xlabel('TIME')
ylabel('COD')
legend('Data','Linear Fit')
axis([xlim 0 11])
It does a linear regression on COD as a function of TIME to create the relationship so it has something to plot, and to demonstrate the technique.
EDIT: Added plot.

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by