Azzera filtri
Azzera filtri

How to plot a list of variables that can change

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Kelly Kearney
Kelly Kearney il 23 Set 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

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by