Skip to content

Instantly share code, notes, and snippets.

@luisdamed
Last active August 12, 2022 14:38
Show Gist options
  • Save luisdamed/b77f7420ac1b280f2fc9fc37e0b7d991 to your computer and use it in GitHub Desktop.
Save luisdamed/b77f7420ac1b280f2fc9fc37e0b7d991 to your computer and use it in GitHub Desktop.
Compare histograms of different data series from a CSV file by creating a bar chart and adding some text with descriptive statistics to the figure. Works with 2020a
%% Read the CSV file
filename = 'test_FSCar_ddMMYYYY_TrackN_setupID2.csv'
t = readtable(filename);
%% Get statistics
meanFL = mean(t.trq_NmFL, 'omitnan')
meanFR = mean(t.trq_NmFR, 'omitnan')
meanRL = mean(t.trq_NmRL, 'omitnan')
meanRR = mean(t.trq_NmRR, 'omitnan')
stdFL = std(t.trq_NmFL, 'omitnan')
stdFR = std(t.trq_NmFR, 'omitnan')
stdRL = std(t.trq_NmRL, 'omitnan')
stdRR = std(t.trq_NmRR, 'omitnan')
%% Prepare text to display
txt = sprintf([ 'mean FL = %1.1f Nm\n', ...
'mean FR = %1.1f Nm\n', ...
'mean RL = %1.1f Nm\n', ...
'mean RR = %1.1f Nm\n\n', ...
'stdev FL = %1.1f Nm\n', ...
'stdev FR = %1.1f Nm\n', ...
'stdev RL = %1.1f Nm\n', ...
'stdev RR = %1.1f Nm\n'], ...
meanFL, meanFR, meanRL, meanRR,...
stdFL, stdFR, stdRL, stdRR)
%% Create figure and add text
figure
hist([t.trq_NmFL, t.trq_NmFR, t.trq_NmRL, t.trq_NmRR],15 , 'normalization')
text( 100 ,45000, txt)
grid on
legend('trq_NmFL', 'trq_NmFR', 'trq_NmRL', 'trq_NmRR', 'interpreter', 'none')
xlabel('Torque')
ylabel('Counts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment