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 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Dyuman Joshi
on 27 Sep 2023
Edited: Dyuman Joshi
on 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
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!