How I can plot 7 graphs on the same X,Y axes

1 view (last 30 days)
I am trying to plot 7 graphs on the same axes. I am using hold on, hold off syntax, but every time it plots only 3 graphs, not the rest. (They all are same and the error line giving is, "Error in Flood_analyzer (line 146) plot(thour, Flood_Area_Tot4);").
I am using a student version, so I am curious whether it has certain datapoint limit in the graphs. (Each graph has 108 (x,y) points).
plot(thour, Flood_Area_Tot1);
hold on
plot(thour, Flood_Area_Tot2);
%hold on
plot(thour, Flood_Area_Tot3);
%hold on
plot(thour, Flood_Area_Tot4);
%hold on
plot(thour, Flood_Area_Tot5);
%hold on
plot(thour, Flood_Area_Tot6);
%hold on
plot(thour, Flood_Area_Tot7);
hold off
The output is...(Only 3 graphs..Why??? :( )
  5 Comments
DGM
DGM on 8 May 2021
Not knowing why it's 1 sample shorter, it's hard to say how to correct it exactly. One can't know if they span the same interval with 1 fewer samples, or if it has the same resolution but is missing the first or last sample.
Regardless, if there are 19000 samples, I doubt it matters for the purpose of the plot. You could just plot it versus thour(1:end-1) and any offset would probably be visually imperceptible.
dpb
dpb on 8 May 2021
As DGM notes, the difference on a plot is probably imperceptible, but if one is doing an analysis, as my grandpa used to say, "If going to do it, might as well do it right!" :)
So, the question then is back to where did the data traces come from and how did you load them? If they came from separate files, it's likely one file didn't have as many points in it as another/the others--if the time is recorded in the file as well, then read it along with the data to keep the two in synch for each file; don't make the blanket assumption that all are the same length that your present code does.
If they are all zero-based and one is just short an observation at the beginning or end, then you can still put them altogether in a single array; just augment the shorter one with a NaN element at the proper place to retain alignment or all traces with each other. This, of course, does presume that the time sample rates are the same across all files as your code above assumes. From the plot you do have, that certainly does appear to be a fair assumption, but we can't know for sure without the data files.

Sign in to comment.

Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!