Bar plot from different .csv files
1 次查看(过去 30 天)
显示 更早的评论
I have 15 .csv files which column 2 is in mm and column 3 is the Newton where I ran three times for the same set. I want the script to read all the files and to make a bar graph where I take the average of each set and calculate the standard deviation. I appreaciate if someone can help me.
3 个评论
Scott MacKenzie
2022-2-27
编辑:Scott MacKenzie
2022-2-28
OK, that's a start. But, it's not clear what you want each "bar graph" to look like. I just looked in the first file. The 1st column contains timestamps for the measurements. The 2nd and 3rd columns contain the measurements for extension (mm) and load (Newtons), respectively. I created some plots of the data in the 2nd and 3rd columns vs. time. Below, the 1st two plots (top row) are line plots and the 2nd two (bottom row) are bar charts showing the means and standard deviations in error bars. I'm not sure that bar graphs are appropriate, given the trends that are evident in the line charts. Please explain in a bit more detail what type of output you want to create. It's also not clear how you want to combine the data from the 15 files. Please explain.
f = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/909015/S1_2_8_25_Specimen_RawData_1.csv';
M = readmatrix(f, 'range', 'a6');
tiledlayout(2,2);
nexttile;
plot(M(:,1), M(:,2));
xlabel('Time (s)'); ylabel('Extension (mm)');
nexttile;
plot(M(:,1), M(:,3));
xlabel('Time (s)'); ylabel('Load (Newtons)')
nexttile;
m1 = mean(M(:,2));
bar(m1);
hold on;
ax = gca;
ax.XTickLabel = {'S1\_2\_8\_25'}; ylabel('Extension (mm)');
errorbar(m1, std(M(:,2)), 'color', 'k');
nexttile;
m2 = mean(M(:,3), 'omitnan');
bar(m2);
hold on;
ax = gca;
ax.XTickLabel = ('S1\_2\_8\_25'); ylabel('Load (Newtons)');
errorbar(m2, std(M(:,3), 'omitnan'), 'color', 'k');
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
