calculating weighted sum of values in a matrix

42 ビュー (過去 30 日間)
Chris Dan
Chris Dan 2021 年 7 月 28 日
編集済み: Jonas 2021 年 7 月 28 日
Hello
I have a short question. I have csv file called "input.csv" which is a 51x3 matrix. I am reading the file and I have to calculate the sum and the weighted sum of the numbers. Weighted sum is the sum of any number multiplied by its row and column index starting at 1 and the sum is addition of all values of a matrix. I have done the sum but how to do the weighted sum. here is my code and I am attaching the file with the question.
a = csvread('input.csv');
S = sum(a,2);
S = sum(S); %1st part
A picture of how the file looks like:

採用された回答

Jonas
Jonas 2021 年 7 月 28 日
編集済み: Jonas 2021 年 7 月 28 日
short example for the weighting: each number is multiplied by its column index and row index
in=ones(3,2);
[X,Y]=meshgrid(1:size(in,2),1:size(in,1));
out=in.*X.*Y
the rest should be easy :)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by