How to plot a list of variables that can change
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Kelly Kearney
2016-9-23
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!