calculate the magnitude of matrix

6 views (last 30 days)
i want to calculate the magnitude of each row, for example row 1 contains the following values (0,20,10), the magnitude of this row is 22.36067977. i want to do the same for the entire list. please help. t=[0:0.4:40]'; s0=zeros(size(t)); b=[s0,s0,10-(t/4).^2]; a=[20*sin(t),20*cos(t),s0]; s0=a+b
s0 =
0 20.0000 10.0000
7.7884 18.4212 9.9900
14.3471 13.9341 9.9600
18.6408 7.2472 9.9100
19.9915 -0.5840 9.8400
18.1859 -8.3229 9.7500
13.5093 -14.7479 9.6400
6.6998 -18.8444 9.5100
-1.1675 -19.9659 9.3600
-8.8504 -17.9352 9.1900
-15.1360 -13.0729 9.0000
-19.0320 -6.1467 8.7900
-19.9233 1.7500 8.5600
-17.6691 9.3703 8.3100
-12.6253 15.5113 8.0400
-5.5883 19.2034 7.7500
2.3310 19.8637 7.4400
9.8823 17.3879 7.1100
15.8734 12.1670 6.7600
19.3584 5.0252 6.3900
19.7872 -2.9100 6.0000
17.0920 -10.3858 5.5900
11.6983 -16.2219 5.1600
4.4578 -19.4969 4.7100
-3.4865 -19.6938 4.2400
-10.8804 -16.7814 3.7500
-16.5565 -11.2197 3.2400
-19.6187 -3.8866 2.7100
-19.5836 4.0601 2.1600
-16.4566 11.3658 1.5900
-10.7315 16.8771 1.0000
-3.3121 19.7238 0.3900
4.6302 19.4567 -0.2400
11.8415 16.1177 -0.8900
17.1832 10.2341 -1.5600
19.8121 2.7347 -2.2500
19.3132 -5.1963 -2.9600
15.7650 -12.3070 -3.6900
9.7280 -17.4747 -4.4400
2.1551 -19.8836 -5.2100
-5.7581 -19.1532 -6.0000
-12.7621 -15.3990 -6.8100
-17.7513 -9.2136 -7.6400
-19.9380 -1.5736 -8.4900
-18.9769 6.3149 -9.3600
-15.0197 13.2063 -10.2500
-8.6913 18.0128 -11.1600
-0.9907 19.9754 -12.0900
6.8663 18.7844 -13.0400
13.6393 14.6277 -14.0100
18.2589 8.1616 -15.0000
19.9959 0.4070 -16.0100
18.5759 -7.4119 -17.0400
14.2232 -14.0606 -18.0900
7.6250 -18.4894 -19.1600
-0.1770 -19.9992 -20.2500
-7.9511 -18.3516 -21.3600
-14.4699 -13.8066 -22.4900
-18.7042 -7.0819 -23.6400
-19.9855 0.7609 -24.8100
-18.1116 8.4836 -26.0000
-13.3782 14.8669 -27.2100
-6.5327 18.9030 -28.4400
1.3442 19.9548 -29.6900
9.0088 17.8561 -30.9600
15.2512 12.9384 -32.2500
19.0857 5.9780 -33.5600
19.9070 -1.9263 -34.8900
17.5855 -9.5264 -36.2400
12.4875 -15.6225 -37.6100
5.4181 -19.2521 -39.0000
-2.5067 -19.8423 -40.4100
-10.0358 -17.2998 -41.8400
-15.9804 -12.0260 -43.2900
-19.4021 -4.8537 -44.7600
-19.7606 3.0850 -46.2500
-16.9994 10.5367 -47.7600
-11.5543 16.3248 -49.2900
-4.2851 19.5356 -50.8400
3.6607 19.6621 -52.4100
11.0285 16.6845 -54.0000
16.6552 11.0727 -55.6100
19.6524 3.7128 -57.2400
19.5469 -4.2333 -58.8900
16.3553 -11.5110 -60.5600
10.5817 -16.9714 -62.2500
3.1374 -19.7524 -63.9600
-4.8022 -19.4149 -65.6900
-11.9837 -16.0122 -67.4400
-17.2731 -10.0816 -69.2100
-19.8356 -2.5593 -71.0000
-19.2664 5.3671 -72.8100
-15.6555 12.4461 -74.6400
-9.5729 17.5602 -76.4900
-1.9790 19.9018 -78.3600
5.9274 19.1015 -80.2500
12.8979 15.2854 -82.1600
17.8322 9.0561 -84.0900
19.9511 1.3970 -86.0400
18.9203 -6.4826 -88.0100
14.9023 -13.3388 -90.0000

Accepted Answer

Birdman
Birdman on 1 Nov 2017
s0_square=s0.^2;
sqrt(sum(s0_square(1:size(s0_square),:)'))'

More Answers (1)

Steven Lord
Steven Lord on 1 Nov 2017
If you're using release R2017b or later, use vecnorm. You'll need to specify both the norm p and the dimension dim to calculate the norm of the rows.

Tags

Community Treasure Hunt

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

Start Hunting!