Storing datetime double in a table

12 visualizaciones (últimos 30 días)
Ieuan Price-davies
Ieuan Price-davies el 18 de Abr. de 2021
Respondida: Stephan el 18 de Abr. de 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 comentarios
Ieuan Price-davies
Ieuan Price-davies el 18 de Abr. de 2021
This is the excel file I'm reading from:
Ieuan Price-davies
Ieuan Price-davies el 18 de Abr. de 2021
Any help on this would be greatly appreciated - thanks!

Iniciar sesión para comentar.

Respuestas (1)

Stephan
Stephan el 18 de Abr. de 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};

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by