How can I properly change a row in my matrix table in excel into letters?
조회 수: 1 (최근 30일)
이전 댓글 표시
nexample = [150, 1, 176, 20, 2000
200, 2, 181, 18, 2300 ]
150, 1, 168, 17, 1900
190, 2, 182, 30, 2400]
nlabels = [{'Weight (lbs) ','Sex','Height (cm)','Age','Calorie Consumption'}];
nexcel = array2table(nexample,'VariableNames', nlabels);
writetable(ncxcel,'example-sheet.xls')
Hello all! I am trying to scan the columns in row 2 and change the numbers to: 1 - Male and 2 - Female so it will show in my excel instead of numbers. What is the best method for doing this? These variables will change depending on user input, so for now this is what I came up with
for col = 1:1:4
if nexample(col,2) == 1
nchange = char(77);
elseif nexcample(col,2) == 2
nchange = char(70); % i would use all the characters if it worked
end
end
Any help is appreciated, i understand it's probably impossible because they aren't the same class. But how do I scan and change it and then replace it with row 2 of the excel sheet?
댓글 수: 0
채택된 답변
Walter Roberson
2022년 12월 7일
Sx = categorical({'Male', 'Female'});
nexcel.('Height (cm)') = Sx(nexcel.('Height (cm)'));
I think people are going to find it somewhat odd to see Height listed as Male or Female...
댓글 수: 3
Walter Roberson
2022년 12월 7일
nexample = [150, 1, 176, 20, 2000;
200, 2, 181, 18, 2300;
150, 1, 168, 17, 1900;
190, 2, 182, 30, 2400]
nlabels = {'Weight (lbs)', 'Sex' ,'Height (cm)','Age','Calorie Consumption'};
nexcel = array2table(nexample,'VariableNames', nlabels);
Sx = categorical({'Male', 'Female'});
nexcel.Sex = reshape(Sx(nexcel.Sex), [], 1);
nexcel
writetable(nexcel,'example-sheet.xls')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!