How can i verify time step of excel files?

조회 수: 2 (최근 30일)
ABDALLAH BOINA Safinati-Amir
ABDALLAH BOINA Safinati-Amir 2019년 11월 24일
편집: Aquatris 2019년 11월 25일
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 ?

채택된 답변

Aquatris
Aquatris 2019년 11월 24일
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
ABDALLAH BOINA Safinati-Amir
ABDALLAH BOINA Safinati-Amir 2019년 11월 24일
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 2019년 11월 24일
편집: Aquatris 2019년 11월 25일
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))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by