Import function automatically converting the datenum values
显示 更早的评论
I need the date read as 'dd/MM/yyyy hh:mm' and I keep getting this suggestion:
Warning: Successfully converted the text to datetime using the
format 'MM/dd/uuuu HH:mm', but the format is ambiguous and could
also be 'dd/MM/uuuu HH:mm'. To create datetimes from text with a
specific format call:
datetime(textinput,'InputFormat',infmt)
but I find myself unable to correctly implement the fix MatLab proposes. I am using a function I made using the import tool, you can see it below:
function puissance = V1_import_puissance(workbookFile, sheetName, startRow, endRow)
%%Input handling
% If no sheet is specified, read first sheet
if nargin == 1 || isempty(sheetName)
sheetName = 1;
end
% If row start and end points are not specified, define defaults
if nargin <= 3
startRow = 2;
endRow = 801; %to make sure I import a file regardless of how big it is. Will import a bunch of empty rows
end
%%Setup the Import Options
opts = spreadsheetImportOptions("NumVariables", 2);
% Specify sheet and range
opts.Sheet = sheetName;
opts.DataRange = "A" + startRow(1) + ":B" + endRow(1);
% Specify column names and types
opts.VariableNames = ["Time", "Puissance"];
opts.VariableTypes = ["datetime", "double"];
%This I where I have tried to implement it :
%datetime(opts,'InputFormat', 'dd/MM/yyyy hh:mm');
% Import the data
puissance = readtable(workbookFile, opts, "UseExcel", false);
for idx = 2:length(startRow)
opts.DataRange = "A" + startRow(idx) + ":B" + endRow(idx);
tb = readtable(workbookFile, opts, "UseExcel", false);
puissance = [puissance; tb]; %#ok<AGROW>
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Calendar 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!