This is the excel file I'm reading from:
Storing datetime double in a table
조회 수: 4 (최근 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
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};
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!