Last active
August 1, 2022 19:00
-
-
Save luisdamed/77e6fff0c5cc9f0bd5a082af0535df3d to your computer and use it in GitHub Desktop.
Matlab code to plot time series data from a csv file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Read the CSV file | |
filename = 'test_FSCar_ddMMYYYY_TrackN_setupID2.csv' | |
t = readtable(filename); | |
%% Index non-empty values and extract time vector | |
idx1 = ~isnan(t.spd_rpmFL); | |
idx2 = ~isnan(t.spd_rpmFR); | |
idx3 = ~isnan(t.trq_NmFL); | |
idx4 = ~isnan(t.trq_NmFR); | |
time = t.Time_s; | |
%% Create a figure with a tiled layout | |
time_series = figure('Name', ['Time series from ' filename], 'Position', [10 10 900 600]); | |
tiles = tiledlayout(2,1); | |
title(tiles, 'MATLAB Plot') | |
xlabel(tiles, 'Time [s]') | |
%% Plot the first set of variables/signals | |
nexttile | |
title('Speed data') | |
hold all | |
plot(t.Time_s(idx1), t.spd_rpmFL(idx1), 'DisplayName', 'spd_rpmFL') | |
plot(t.Time_s(idx2), t.spd_rpmFR(idx2), 'DisplayName', 'spd_rpmFR') | |
xlim([600, 650]) | |
ylabel('Speed [rpm]') | |
grid minor | |
legend('interpreter', 'none') | |
ax1 = gca; | |
%% Plot a second set of variables/signals | |
nexttile | |
title('Torque data') | |
hold on | |
plot(t.Time_s(idx3), t.trq_NmFL(idx3), 'DisplayName', 'trq_NmFL') | |
plot(t.Time_s(idx4), t.trq_NmFR(idx4), 'DisplayName', 'trq_NmFR') | |
ax2 = gca; | |
xlim([600, 650]) | |
ylabel('Torque [Nm]') | |
grid minor | |
legend('interpreter', 'none') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment