Plot multiple lines from multiple tables

40 次查看(过去 30 天)
I'm trying to process data from fortran and i want to plot the radius over time from lots of different tables that i've read using
filename7='24.dat'
T7=readtable(filename,"VariableNamingRule","preserve")
T7=renamevars(T7, ["Var1", "Var2", "Var3", "Var4"], ["Time","Ts","Rd","Teff"])
filename2='90.dat'
T2=readtable(filename2,"VariableNamingRule","preserve")
T2=renamevars(T2, ["Var1", "Var2", "Var3", "Var4"], ["Time","Ts","Rd", "Teff"])
but i've got up to 12 different tables named T1- 12
this is what i used to make individual plots
filename2='90.dat'
T2=readtable(filename2,"VariableNamingRule","preserve")
T2=renamevars(T2, ["Var1", "Var2", "Var3", "Var4"], ["Time","Ts","Rd", "Teff"])
plot(T2.Time, T2.Rd)
grid on
xlabel('Time [ms]')
ylabel('Droplet Radius [um]')
title('Pure SME Droplet Lifetime 90 QCs ')
filename7='24.dat'
T7=readtable(filename7,"VariableNamingRule","preserve")
T7=renamevars(T7, ["Var1", "Var2", "Var3", "Var4"], ["Time","Ts","Rd","Teff"])
plot(T7.Time, T7.Rd)
grid on
xlabel('Time [ms]')
ylabel('Droplet Radius [um]')
title('Pure SME Droplet Lifetime 24 QCs ')
How can i plot the a specific column (radius) from all the tables over time as its the same time step for all of them so i can end up with something similar to this:

采纳的回答

Stephen23
Stephen23 2021-3-18
编辑:Stephen23 2021-3-18
By numbering your variables like that you have made the task a lot harder and more complex.
The simpler and much more efficient solution is to use indexing, something like this:
S = ["90.dat","24.dat"]; % string array of all filenames.
for k = 1:numel(S)
T = readtable(S(k),"VariableNamingRule","preserve");
T = renamevars(T, ["Var1", "Var2", "Var3", "Var4"], ["Time","Ts","Rd", "Teff"])
plot(T.Time, T.Rd)
hold on
end
grid on
xlabel('Time [ms]')
ylabel('Droplet Radius [um]')
title('Pure SME Droplet Lifetime')
Note that you can add a legend and supply the (possibly modified) filenames as labels for the plotted lines. You can also control the line color and linestyle, as explained in the plot documentation.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by