How can i verify time step of excel files?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!