How can i verify time step of excel files?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
ABDALLAH BOINA Safinati-Amir
el 24 de Nov. de 2019
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 comentarios
Respuesta aceptada
Aquatris
el 24 de Nov. de 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 comentarios
Aquatris
el 24 de Nov. de 2019
Editada: Aquatris
el 25 de Nov. de 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))
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!