MATLAB Answers

How can i verify time step of excel files?

1 view (last 30 days)
Hello,
I have several excel files (.xlsx) with time data how can i check that the time step is th same in all files and that it does not lack ?

  0 Comments

Sign in to comment.

Accepted Answer

Aquatris
Aquatris on 24 Nov 2019
After you load the file in to matlab workspace, name the variable for time. Then you can use diff() function to find the difference in consecutive values.
Assume your time variable is t, then if you do
plot(diff(t))
then, the plot will show you the time steps.

  2 Comments

ABDALLAH BOINA Safinati-Amir
Can you show me an example please? When i try the fonction load it does not work. I don't know why.
Thanks.
Aquatris
Aquatris on 24 Nov 2019
I reccommend you use the "Import Data" functionality. From there you can load your data as column vector. Then you can generate a script that does it automatically for you so that as long as your excel sheets are in the same format, you can reuse the loading script for different files by simply changing the name of the file in the script.
You can also open the "Import Data" functionality if you drag and drop the excel file into the Command Window which is equaivalent to using the below command
% excel file to be used C:\Users\PC1\Desktop\New Microsoft Excel Worksheet.xlsx
uiopen('C:\Users\PC1\Desktop\New Microsoft Excel Worksheet.xlsx',1)
Here is an example script that "Import File" generates for a worksheet that has column A with "time" values and column B for "data".
%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: C:\Users\PC1\Desktop\New Microsoft Excel Worksheet.xlsx
% Worksheet: Sheet1
%
% Auto-generated by MATLAB on 24-Nov-2019 05:04:36
%% Setup the Import Options
opts = spreadsheetImportOptions("NumVariables", 2);
% Specify sheet and range
opts.Sheet = "Sheet1";
opts.DataRange = "A2:B35";
% Specify column names and types
opts.VariableNames = ["time", "data"];
opts.VariableTypes = ["double", "double"];
% Import the data
tbl = readtable("C:\Users\PC1\Desktop\New Microsoft Excel Worksheet.xlsx", opts, "UseExcel", false);
%% Convert to output type
time = tbl.time;
data = tbl.data;
%% Clear temporary variables
clear opts tbl
%to visualize the time step
plot(diff(time))

Sign in to comment.

More Answers (0)

Sign in to answer this question.