How to plot a list of variables that can change
5 views (last 30 days)
Show older comments
Gregory McFadden
on 23 Sep 2016
Answered: Kelly Kearney
on 23 Sep 2016
Here is what I am trying to figure out what to do. I have a particular type of datafile that has N sets of X-Y data that are all to be plotted on the same scale. The number N can vary datafile to datafile. The data can not all be added to the same matrix and plotted using the same X vector because the length of each set of data and the points in X can be different.
I have not found a robust way to plot all the input data regardless of how many sets of data are in one file. I can get all the data in (Right now it goes into a N numbered structured variable, E.G Data.N1.XY stores the matrix for the first set of data in the file, the script increments up through the data to Data.Nx.XY for the last. I have not found a good way to plot all of the sets of data on the same plot that can adapt to the varying number of sets of data. Any ideas?
0 Comments
Accepted Answer
Kelly Kearney
on 23 Sep 2016
Don't name your structure fields using hard-coded numbers like that; instead, use an array:
Data.N(1).XY = rand(10,2);
Data.N(2).XY = rand(15,2);
Then, when you want to plot, you can simply loop over this:
axes; hold on;
for ii = 1:length(Data.N)
h(ii) = plot(Data.N(ii).XY(:,1), Data.N(ii).XY(:,2));
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!