How do I add column headers (variable names) to a dummyvar table?
이전 댓글 표시
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
Douglas Leaffer
2023년 6월 13일
Douglas Leaffer
2023년 6월 13일
Let me try to run it:
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
Oops! It looks like you forgot to attach data. We'll check back later. In the meantime, setting properties and using addvars should work.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Deepak Gupta
2023년 6월 13일
@Image Analyst I don't think you need data to understand the problem user is trying to demostrate. It's evidently clear from the output and writeup he has written.
Deepak Gupta
2023년 6월 13일
@Douglas Leaffer Simplest way to do it is convert your table back to an array using x = table2array(CMET4) and than convert back to a table y = array2table(x). It will separate out each column. You can assign new variable names using y.Properties.VariableNames = {'a' 'b' 'c' 'd' 'e'}
Douglas Leaffer
2023년 6월 13일
답변 (1개)
Douglas Leaffer
2023년 6월 13일
이동: Image Analyst
2023년 6월 13일
카테고리
도움말 센터 및 File Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
