Bar plot from different .csv files
1 view (last 30 days)
Show older comments
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 Comments
Scott MacKenzie
on 27 Feb 2022
Edited: Scott MacKenzie
on 28 Feb 2022
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');
Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!