How can I properly change a row in my matrix table in excel into letters?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Karl
am 7 Dez. 2022
Kommentiert: Walter Roberson
am 7 Dez. 2022
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Dez. 2022
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 Kommentare
Walter Roberson
am 7 Dez. 2022
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')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!