Filter löschen
Filter löschen

How to plot a list of variables that can change

2 Ansichten (letzte 30 Tage)
Gregory McFadden
Gregory McFadden am 23 Sep. 2016
Beantwortet: Kelly Kearney am 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?

Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 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

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by