How to produce a graph with 2 sets of data on matlab?

113 views (last 30 days)
Hi everyone, so i've created a code that solves an iteration for me that gives me the correct Temperature for a composition.
This leads to me needing to code for a graph Bubble Point Temperature v Composition and Dew Point Temperature v Composition.
Both in 1 graph so that I have 2 curves in the same graph.
How would I go about doing this?
Also is there a way for the graph to be produced automatically right after the code i have already coded of for provides me with the temperature?
If this doesn't make sense i'm more than happy to re-explain, i'm currently pretty sleep deprived haha.
Any help is appreciated!

Answers (2)

Star Strider
Star Strider on 9 Nov 2015
There are several ways. The easiest way is to use the hold function.
Example:
figure(1)
plot(x1, y1)
hold on
plot(x2, y2)
hold off
grid
  7 Comments
Thorsten
Thorsten on 10 Nov 2015
You have 12 elements in Temperature1, but only 11 in x and Temperature. Get rid of one element in Temperature1 and you are done.
Star Strider
Star Strider on 10 Nov 2015
Edited: Star Strider on 10 Nov 2015
You have to have the same number of elements in x and Temperature in the first plot, and x and Temperature1 in the second.
One way to do that is to create x1 and x2:
x1 = linspace(0, 1, length(Temperature));
x2 = linspace(0, 1, length(Temperature1));
figure(1)
plot(x1, Temperature)
hold on
plot(x2, Temperature1)
hold off
grid
legend('Temperature', 'Temperature1')
xlabel('x')
ylabel('Temperature (°C)')

Sign in to comment.


Thorsten
Thorsten on 10 Nov 2015
Edited: Thorsten on 10 Nov 2015
I deleted the final element of Temperature1, such that x, Temperature, and Temperature1 have the same number of elements:
x = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1];
Temperature = [272.78, 262.92, 259.74, 258.66, 258.30, 258.19, 258.18, 258.27, 258.68, 260.31, 266.70];
Temperature1 = [272.8, 270.4, 267.9, 265.2, 262.3, 259.3, 258.3, 258.5, 260.6, 262.7, 264.8];
To plot, use:
plot(x, Temperature)
hold on
plot(x, Temperature1)
or
plot(x, Temperature, x, Temperature1)
or
plot(x, [Temperature; Temperature1]')

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!