How to plot a list of variables that can change
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gregory McFadden
el 23 de Sept. de 2016
Respondida: Kelly Kearney
el 23 de Sept. de 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 comentarios
Respuesta aceptada
Kelly Kearney
el 23 de Sept. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!