Storing datetime double in a table

13 ビュー (過去 30 日間)
Ieuan Price-davies
Ieuan Price-davies 2021 年 4 月 18 日
回答済み: Stephan 2021 年 4 月 18 日
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 件のコメント
Ieuan Price-davies
Ieuan Price-davies 2021 年 4 月 18 日
This is the excel file I'm reading from:
Ieuan Price-davies
Ieuan Price-davies 2021 年 4 月 18 日
Any help on this would be greatly appreciated - thanks!

サインインしてコメントする。

回答 (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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by