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?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dyuman Joshi
2023-9-27
编辑:Dyuman Joshi
2023-9-27
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
更多回答(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!