Storing datetime double in a table

8 次查看(过去 30 天)
Hi there,
I'm currently trying to read a datetime from one table and then write it into another, for some reason when I try and do this however I get the following error:
"The following error occurred converting from table to double:
"Undefined function 'double' for input arguments of type 'table'. To convert to numeric, use the TABLE2ARRAY function, or extract data using
"dot or brace subscripting.
Could anyone help me with this error please?
This is the code I have that reads in the inital excel file and stores it in a table called "data"
%%%Set this to desired sheet
sheet = 'Test';
global data
%Sets Date time format for when table is read
opts = detectImportOptions("Weather data - polysun.xlsx","Sheet",sheet);
opts = setvartype(opts,"Date","datetime");
opts = setvaropts(opts,"Date",'InputFormat','dd.MM. HH:mm');
%Names each column and reads table with desired options
opts.VariableNames = ["Index","Date","NormDirectIrradiation","DiffuseIrradiation","GlobalIrradiation","AirHumidity","LongWavelengthIrradiation","OutdoorTemp24h","WindSpeed","OutdoorTempAve"];
data = readtable("Weather data - polysun.xlsx",opts);
Then this code here loops through the data and should add the date: data(i,2) to a new table named "Results"
%creates data table to store temperature/power values in
Results = array2table(zeros(height(data),12));
Results.Properties.VariableNames = ["Date","AmbientTemp","SkyTemp","GlassTemp","PVTemp","AbsorberTemp","Irradiance","WindSpeed","Power","WaterTemp","Efficiency","Heat Transfer"];
for i = 1: height(data)
%Read data from the table
%Adds Date
Results.Date(i) = data(i,2);
end

回答(1 个)

Stephan
Stephan 2021-4-18
%%%Set this to desired sheet
sheet = 'Test';
%Sets Date time format for when table is read
opts = detectImportOptions("Weather data - polysun.xlsx","Sheet",sheet);
opts = setvartype(opts,"Date","datetime");
opts = setvaropts(opts,"Date",'InputFormat','dd.MM. HH:mm');
%Names each column and reads table with desired options
opts.VariableNames = ["Index","Date","NormDirectIrradiation","DiffuseIrradiation","GlobalIrradiation","AirHumidity","LongWavelengthIrradiation","OutdoorTemp24h","WindSpeed","OutdoorTempAve"];
data = readtable("Weather data - polysun.xlsx",opts);
%creates data table to store temperature/power values in
Results = array2table(zeros(height(data),12));
Results.Properties.VariableNames = ["Date","AmbientTemp","SkyTemp","GlassTemp","PVTemp","AbsorberTemp","Irradiance","WindSpeed","Power","WaterTemp","Efficiency","Heat Transfer"];
Results.Date = data{:,2};

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by