How to work with several groups of data?

2 views (last 30 days)
Adam Smith
Adam Smith on 26 Oct 2015
Answered: Peter Perkins on 26 Oct 2015
I have a bunch of data stored as several .csv files. I want to plot and compare the data from the different sets. For example I have csv files 10Flap.csv, 20Flap.csv and 30Flap.csv each of which has columns for Pitch, Cl, Cd, Cw etc. I can do this by importing them as matrices and using lots of indexing, or I can import them as tables and do:
hold on
plot(10Flap.Pitch,10Flap.Cl);
plot(20Flap.Pitch,20Flap.Cl);
plot(30Flap.Pitch,30Flap.Cl);
However I have a lot of these files and need to have several plots with different selections plotted together so I would like to be able to do something like:
hold on
for data=[10Flap, 20Flap, 30Flap]
plot(data.Pitch,data.Cl);
end
If I try this I get an error because each set of data has a different number of rows.
Is there any way to do this or am I best off writing everything out in full?
Thanks in advance for the help!

Answers (1)

Peter Perkins
Peter Perkins on 26 Oct 2015
One possibility would be to store the tables (or matrices) as fields of a scalar struct, with field names like 10Flap. Actually, not exactly like 10Flap, it'd have to be Flap10 or whatever. Then use structfun to make all the plots. Similarly you could put the tables in a cell array, one per cell, and loop over that array.
Another possibility, perhaps more flexible, would be to vertically concatenate them, with the addition of a categorical variable whose categories are 10Flap, etc., then in each iteration of the loop create a logical vector as something like
i = flapData.Flap == '10Flap'
and plot only that subset of rows. All depends on how you want to organize things.
Hope this helps.

Categories

Find more on 2-D and 3-D 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!