Filter löschen
Filter löschen

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

23 Ansichten (letzte 30 Tage)
Douglas Leaffer
Douglas Leaffer am 13 Jun. 2023
Bearbeitet: Matt J am 13 Jun. 2023
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 Kommentare
Matt J
Matt J am 13 Jun. 2023
Bearbeitet: Matt J am 13 Jun. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Douglas Leaffer
Douglas Leaffer am 13 Jun. 2023
Verschoben: Image Analyst am 13 Jun. 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 );

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by