Azzera filtri
Azzera filtri

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

23 visualizzazioni (ultimi 30 giorni)
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 Commenti
Matt J
Matt J il 13 Giu 2023
Modificato: Matt J il 13 Giu 2023
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

Accedi per commentare.

Risposte (1)

Douglas Leaffer
Douglas Leaffer il 13 Giu 2023
Spostato: Image Analyst il 13 Giu 2023
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 );

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by