how to plot a diagram that includes many excel data?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Athena Argyropoulou
el 28 de Feb. de 2024
Comentada: Star Strider
el 29 de Feb. de 2024
hello everyone. I have a problem with finding an approprieate program in matlab.
I have specifically 173 excel files including a sheet of time data and a sheet of many concentration data from different chemical compounds. The excel files are connected as the time continues in every file. My task is to find the averages of both time and concentration per 5 minutes and per 1 hour and plot seperately each chemical compound concentration with time ( one diagram every time). The problem is that i dont know how to insert all of the excel files and connect the data
5 comentarios
Respuesta aceptada
Star Strider
el 28 de Feb. de 2024
Editada: Star Strider
el 29 de Feb. de 2024
One approach is to read the files in to separate cell arrays, then vertically concatenate them, and then choose the ‘Absolute Time’ column from the concatenated ‘Time’ sheet and horizontally concatenate it with the ‘Concentration’ sheet to get the result.
Try this —
files = dir('*.xlsx');
for k = 1:numel(files)
shnm = sheetnames(files(k).name);
% Choose_Sheets = shnm([2 4])
Time{k,:} = readtable(files(k).name, 'VariableNamingRule','preserve', 'Sheet',2);
Start_Stop = Time{k}([1 end],:)
Conc{k,:} = readtable(files(k).name, 'VariableNamingRule','preserve', 'Sheet',4);
end
Timevc = vertcat(Time{:});
Concvc = vertcat(Conc{:});
Time_Conc = [Timevc(:,2) Concvc]
VN = Time_Conc.Properties.VariableNames;
figure
plot(Time_Conc{:,1}, Time_Conc{:,2:6}) % Plot Some Example Data
grid
xlabel('Time')
ylabel('Concentration')
title('Concentration Data')
legend(VN{2:6}, 'Location','best')
EDIT — (29 Feb 2024 at 01:37)
If the Excel files are not imported in sorted order, to sort them by time, add:
Time_Conc = sortrows(Time_Conc,1);
after creating the concatenated ‘Time_Conc’ table (in my code, name it appropriately for your needs).
.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets 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!