Dividing a row in a table by its first entry which results in a new column with a 1*1 table in each row. How can i change it to the number?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I want to normalize my row by dividing it by its first entry. Which I'm doing in the following way.
D1990.pricenorm = D1990(:,"priceadj")./D1990(1,"priceadj");
Where D1990 is the table, pricenorm the new column and priceadj the column I want to normalize.
My code gives me the right result but stores it as 1*1 table instead of just the number. I attached a picture to be clear what I mean.
How can I fix it? Thank you in advance.
0 commentaires
Réponse acceptée
Dyuman Joshi
le 27 Sep 2023
Modifié(e) : Dyuman Joshi
le 27 Sep 2023
As I don't have your data, I'm using random data -
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(LastName,Age,Smoker,Height,Weight,BloodPressure)
> Using parenthesis with Column name yields a sub table -
T(:,"Weight")
As you operate on a table, the output you will also be a table.
> Solution - You can use curly brackets
T.BMI = T{:,"Weight"}./T{:,"Height"}.^2
Or dot notation
T.BMI = T.("Weight")./T.("Height").^2
Read more here - Access data in a table
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!