Calculate Standard deviation in table

Hi,
I have a table with 20 columns, I want to make a new column with the standard deviation of each row from column 4 to 6.
So after column 6 i want to have a column with the stdev of all rows of column 4:6.
How can I do that?

 Accepted Answer

a = array2table(rand(5,8)) % Sample table
a = 5×8 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 _______ _______ _______ _________ _______ _________ _______ _______ 0.4022 0.9627 0.53548 0.35205 0.70636 0.89738 0.50393 0.44203 0.96785 0.33289 0.57833 0.36493 0.84985 0.0031283 0.34461 0.3312 0.29543 0.18861 0.91065 0.025623 0.40162 0.88419 0.24007 0.38235 0.66403 0.19131 0.24685 0.0092594 0.10672 0.51052 0.79236 0.43115 0.62483 0.95579 0.37075 0.11087 0.65024 0.55079 0.97985 0.57458
s = std(a{:, 4:6}, [], 2) % std along rows (dim=2)
s = 5×1
0.2767 0.4249 0.4304 0.2658 0.2870
b = [a table(s, 'VariableNames', {'std'})] % combine with original
b = 5×9 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 std _______ _______ _______ _________ _______ _________ _______ _______ _______ 0.4022 0.9627 0.53548 0.35205 0.70636 0.89738 0.50393 0.44203 0.27671 0.96785 0.33289 0.57833 0.36493 0.84985 0.0031283 0.34461 0.3312 0.42485 0.29543 0.18861 0.91065 0.025623 0.40162 0.88419 0.24007 0.38235 0.43038 0.66403 0.19131 0.24685 0.0092594 0.10672 0.51052 0.79236 0.43115 0.26577 0.62483 0.95579 0.37075 0.11087 0.65024 0.55079 0.97985 0.57458 0.28704

More Answers (1)

If you want to calculate the standard deviation of the whole table:
For example "cax" is table.
1.6424 5.2601 1.4691 0.7361 0.2771
1.0531 0.5722 1.8804 4.9636 0.9451
1.8084 1.6537 1.5916 0.8352 0.7740
0.7550 1.4221 1.7003 2.5646 0.4272
2.2935 2.5158 0.7656 1.0110 2.0810
1.0765 0.5390 1.9687 2.0829 0.4572
1.0493 1.4736 1.2810 1.0911 0.2073
2.1630 0.5679 2.8582 1.6006 0.4746
1.1625 0.7333 0.2623 0.6887 0.7897
2.9148 0.2886 3.1662 0.3645 0.5730
std(cax,[],'all')
ans =
1.0786e+03

Categories

Products

Release

R2020b

Asked:

on 25 Jun 2021

Answered:

on 24 Jan 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!