Storing datetime double in a table

12 views (last 30 days)
Ieuan Price-davies
Ieuan Price-davies on 18 Apr 2021
Answered: Stephan on 18 Apr 2021
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
  2 Comments
Ieuan Price-davies
Ieuan Price-davies on 18 Apr 2021
Any help on this would be greatly appreciated - thanks!

Sign in to comment.

Answers (1)

Stephan
Stephan on 18 Apr 2021
%%%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};

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!