Plot serial time data from excel file
9 views (last 30 days)
Show older comments
Hello.
I am trying to plot data from excel file. Column 2 (amplitude) vs Column 1 (time). The time is in second
Each second the data is sample 200 time.
0.000 (second zero sample zero) => 0.199 (second zero to sample 199) to second 120.004 (120 second. sample 004).
I try writing a code, but I am not able to make it work.
Also, I am trying to plot the results where xlabel show that each second there are 200 samples.
I have try some codes.
% Define the sampling parameters
Fs = 200; % Sampling frequency in Hz
duration = 5.199; % Duration in seconds
t = 0:1/Fs:duration; % Time vector from 0 to 5.199 seconds
% Read data from Excel file
data = readtable('HUAM1709.041_v3.xlsx'); % Replace with your actual file name
amplitude = data.Var2; % Assuming the second column contains the amplitude data
% Ensure the time vector matches the length of the amplitude data
if length(amplitude) ~= length(t)
error('Length of amplitude data does not match the time vector.');
end
% Plot the discrete time series data
figure;
stem(t, amplitude, 'filled'); % Use stem for discrete data representation
xlabel('Time (seconds)');
ylabel('Amplitude');
title('Discrete Time Series Data from 0 to 5.199 seconds');
grid on;
This code was thanks to Star Strider (Level 10 Mathworks)
data = readtable('HUAM1709.041_v2.xlsx')
% return
T = data{:,1};
T = seconds(data{:,1});
T.Format = 'hh:mm';
T2 = data{:,2};
figure; % Place "figure" in this section allow to plot this data in a separate window.
plot (T,T2,'.');
title 'Accelerometer';
ylabel ('Amplitude');
xlabel ('Samples');
I am looking a plot like the attached file.
Where X axis is going from 0 to 120.
Accepted Answer
Star Strider
on 8 Oct 2025
Your data does not look like the data in the image file.
I made some changes (additions) to your code to plot only the 't' and 'amplitude' values you define in your code that correspond to the 'duration' limit. I used 'data.Var1' as the time vector. I then determined the length (in seconds) of 't' and calculated the logical vector 'Lv' to select only those values of 't' that are less than 'duration'. I then used that logical vector to extract a matching length section of 'amplitude'. (I linked to the Excel file you posted in your earlier Question.)
file = websave('HUAM1709.041_v2.xlsx','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1841254/HUAM1709.041_v2.xlsx')
% Define the sampling parameters
Fs = 200; % Sampling frequency in Hz
duration = 5.199; % Duration in seconds
t = 0:1/Fs:duration; % Time vector from 0 to 5.199 seconds
% Read data from Excel file
% data = readtable('HUAM1709.041_v3.xlsx'); % Replace with your actual file name
data = readtable(file)
amplitude = data.Var2; % Assuming the second column contains the amplitude data
% Fs_from_time_vector = 1/mean(diff(data{:,1}))
[tmin,tmax] = bounds(data{:,1})
Lv = data.Var1 <= duration; % Logical Vector To Select Values Of The Time Vector ('data.Var1)' <= 'duration'
t_lim = data.Var1(Lv); % Limited Time Vector
amplitude_lim = amplitude(Lv); % Limited 'amplitude' Vector
% Ensure the time vector matches the length of the amplitude data
% if length(amplitude) ~= length(t)
% error('Length of amplitude data does not match the time vector.');
% end
% Plot the discrete time series data
figure;
% stem(t, amplitude, '.', 'filled'); % Use stem for discrete data representation
stem(t_lim, amplitude_lim , '.', 'filled')
xlabel('Time (seconds)');
ylabel('Amplitude');
title('Discrete Time Series Data from 0 to 5.199 seconds');
grid on;
This uses your selected values to plot the selected variables.
Plotting the other ones similarly --
for k = 1:2
figure
plot(t_lim, data{Lv,k+2})
grid
xlabel('t')
ylabel('Variable')
title("Column "+(k+2))
end
..
This is the best I can do with your data.
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


