How to plot multiple data sets on the same graph

The following coding is only plotting the first two variables on the plot.
plot(years,run_rate,'r-s',years,CL,'g-',years,UCL,'g-',years,LCL,'g-');

 Risposta accettata

Use hold on command between. For instance:
plot(years,run_rate,'r-s');hold on;plot(years,CL,'g-');hold on;plot(years,UCL,'g-');hold on;plot(years,LCL,'g-')

5 Commenti

Aamna Sami
Aamna Sami il 9 Dic 2017
Modificato: Aamna Sami il 9 Dic 2017
I tried that but it did not work. I think the problem lies in the fact that the variables CL,UCL and LCL are scalars and the variable years is a matrix. Do you know what should be done in the that case?
Try the following for each scalar variables, but do not forget you need a vector instead of a matrix. So consider that you take the first column of years matrix, which is denoted as
years(:,1)
Try the following for scalars. The variables should have same length.
CL=CL*ones(length(years(:,1)),1)
UCL=UCL*ones(length(years(:,1)),1)
LCL=LCL*ones(length(years(:,1)),1)
This worked! Thank you!
Can you accept the answer so that other people having the same problem will know there is a working solution.
Sure:) Thanks again for your prompt responses!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by