find sum of each row

1 回表示 (過去 30 日間)
Giannakis Stoukas
Giannakis Stoukas 2015 年 3 月 21 日
コメント済み: Star Strider 2015 年 3 月 22 日
Hello,i have a vector named dem(101) and a matrix routes(21,14) that has inside the numbers 1,2,3,4 etc. for example the first row of the matrix is the routes(1,14)=[1 21 25 26 28 30 31 29 24 23 22 48 1]. I want to save to a matrix named load(21) the sum of every route by the vector dem.For example i want the load(1)=sum(dem[1] dem[21] dem[25] dem[26]...... etc)

採用された回答

Star Strider
Star Strider 2015 年 3 月 21 日
I don’t understand your matrix structure, but this will do the calculation you described:
dem = randi(25, 1, 101);
routes = [1 21 25 26 28 30 31 29 24 23 22 48 1];
load = sum(dem(routes));
This illustrates the details of the addressing:
dem_routes = dem(routes); % Check
I include it for illustration only. It is not part of the code.
  4 件のコメント
Giannakis Stoukas
Giannakis Stoukas 2015 年 3 月 22 日
Yes i had one zero element without noticing it.Thank you for your respond
Star Strider
Star Strider 2015 年 3 月 22 日
My pleasure!
It should work without the zero element.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by