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!