Plot multiple lines from multiple tables

40 ビュー (過去 30 日間)
Elodie Newman
Elodie Newman 2021 年 3 月 18 日
コメント済み: Elodie Newman 2021 年 3 月 19 日
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.
  1 件のコメント
Elodie Newman
Elodie Newman 2021 年 3 月 19 日
Thankyou!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-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