summation of matrix function

4 ビュー (過去 30 日間)
satish
satish 2023 年 4 月 8 日
回答済み: Torsten 2023 年 4 月 8 日
I have matrix(8x8) which is content of x and y. I need summation of matrix for(x1,y1), (x2,y2), (x3,y3) and (x4,y4). please help me.

回答 (2 件)

Vilém Frynta
Vilém Frynta 2023 年 4 月 8 日
this looks like homework.
i'll try to guide you, but be aware that you won't learn anything by letting others do your homework for you.
m = randi(10, [8 8]) % 8x8 matrix
m = 8×8
4 5 9 6 8 5 4 9 1 10 1 6 6 10 3 9 1 3 8 6 1 9 4 6 2 7 2 3 5 8 9 3 3 10 5 9 4 3 2 9 9 2 3 8 10 7 7 9 7 1 10 1 6 5 1 8 8 6 7 9 3 2 10 5
if you use sum() on the whole matrix, you would get sums from all the columns. if you only want to get sum from specific columns, you can specify that by indexing.
sum(m(:,1)) % sum of all rows from column 1
ans = 35
if you wish to make sums of rows, you will need to rotate (transpose) the matrix.

Torsten
Torsten 2023 年 4 月 8 日
s = m(1,1)+m(2,2)+m(3,3)+m(4,4)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by