Convert Column to be header ?

2 次查看(过去 30 天)
Shahrul Azman
Shahrul Azman 2021-5-9
评论: dpb 2021-5-9
Hello,
Today is my 6th day learning matlab.
I have 2 problem
1)My table didnt show as 50000X7 column instead 2 column as below.
PV11' [1x7 double]
'PV12' [1x7 double]
'PV13' [1x7 double]
2) I no idea to transform column value to become header.
I have uploaded my code and mat file.
My code as below :
RawIrr = readtable("TrainingData.txt")
load ("TrainingTstc.mat")% name in workspace = Tstc
load ("TrainingAlpha.mat") % name in workspace = Alpha_pmp
load ("PVModel.mat") % name in workspace = T1
P1 = RawIrr (:,1);%DateAndTime
P2 = RawIrr (:,2);%Air Temp
P4 = RawIrr (:,4);%DNI
DateTime = table2array(P1);
AirTemp = table2array(P2);
DNI = table2array(P4);
FtempN = 1 + Alpha_pmp.* (AirTemp(:,1)' - Tstc); % get 50000 X 7
%next line to restructure back data PVmodel
FtempFinal = table(T1,FtempN(:,:))
but matlab return result like below
PV11' [1x7 double]
'PV12' [1x7 double]
'PV13' [1x7 double]
i would like to put DateAndTime as header but i tried many time but no luck.
my final result should as below. I want to put date and time as header .is it possible?
50000X7 table
31/12/0018 08:15:00 31/12/0018 08:30:00 31/12/0018 08:45:00 31/12/0018 09:00:00 31/12/0018 09:15:00 31/12/0018 09:30:00
PV1 1.0056 1.0048 1.004 1.0036 1.0028 1.0024
PV2 1.0056 1.0048 1.004 1.0036 1.0028 1.0024
PV3 1.0057 1.0049 1.004 1.00369 1.00287 1.00246
Thanks sir.
Thank you for your great support.
  1 个评论
dpb
dpb 2021-5-9
You don't want 50,000 columns of date and time as column headers in a table, no. That will NOT be conducive to using the data --
It's not at all clear why you have the small table of only seven elements at all here?
And, your code snippet above loads variables Tstc, Alpha_pmp, and T1, each of which are 50K by 1 vectors, but where's the required AirTemp variable of the same size--the P1, P2, P4 variables from the table that are defined aren't but the eight-long vectors from the short table. And, what is DNI?
The T1 variable turns out to be an (apparently) categorical vector of some model type it appears; we find that>> numel(unique(T1.PVModel)) = 20.
It looks as though these data could/would be ideal for a timetable of the 50K observations times with whichever of these other variables are wanted/need as the columns, one of which undoubtedly should be the above categorical of which model is which record.
One then could easily use varfun and grouping variables to operate over those records of each model as desired -- but trying to organize the other-way-round with the time values as the columns and column headers will not work well at all for 50,000 time records.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by