How do I add column headers (variable names) to a dummyvar table?

15 次查看(过去 30 天)
I could use some help adding column headers (variable names) to a dummyvar table? My code is attached. The table (tbl) once converted to an array, below, shows only 1 column header, but I need to show 4 distinct column headers and then add that matrix to another table. Thank you.
tempSector = dummyvar(categorical(ImpactWind));
WindOther = tempSector(:,1);
WindRail = tempSector(:,2);
WindAirport = tempSector(:,3);
WindRoad = tempSector(:,4);
tbl = table(WindOther,WindRail,WindAirport,WindRoad);
% tbl.Properties.VariableNames = {'WindOther','WindRail','WindAirport','WindRoad'};
IW = tbl{:,:}; % IW = table of ImpactWind dummyvars
CMET4 = addvars(CMET3, IW); % CMET3 is a matrix of other meterological parameters
  8 个评论
Matt J
Matt J 2023-6-13
编辑:Matt J 2023-6-13
please Run your code here in the forum, using the instructions in the link I gave you. Example,
T=array2table(rand(5,3))
T = 5×3 table
Var1 Var2 Var3 _______ _______ _______ 0.7859 0.65929 0.65119 0.25801 0.1189 0.7871 0.1786 0.42362 0.54381 0.84239 0.74138 0.20506 0.79453 0.51149 0.8186
newvar=rand(5,1);
T=addvars(T,newvar)
T = 5×4 table
Var1 Var2 Var3 newvar _______ _______ _______ ________ 0.7859 0.65929 0.65119 0.91629 0.25801 0.1189 0.7871 0.82619 0.1786 0.42362 0.54381 0.16378 0.84239 0.74138 0.20506 0.1588 0.79453 0.51149 0.8186 0.088069

请先登录,再进行评论。

回答(1 个)

Douglas Leaffer
Douglas Leaffer 2023-6-13
移动:Image Analyst 2023-6-13
Code file is too large to upload ... ... I did it the 'brute force' method
WindOther = tbl.WindOther; WindRail = tbl.WindRail;
WindAirport = tbl.WindAirport; WindRoad = tbl.WindRoad;
IW = table2array(tbl,'VariableNames', {'WindOther','WindRail','WindAirport','WindRoad'});
%IW = tbl{:,:}; % table of wind impact dummyvars
CMET4 = addvars(CMET3, WindAirport, WindRoad, WindRail, WindOther );

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by