Plot multiple lines from multiple tables

37 visualizaciones (últimos 30 días)
Elodie Newman
Elodie Newman el 18 de Mzo. de 2021
Comentada: Elodie Newman el 19 de Mzo. de 2021
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:

Respuesta aceptada

Stephen23
Stephen23 el 18 de Mzo. de 2021
Editada: Stephen23 el 18 de Mzo. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by