Using symsum for arrays

2 ビュー (過去 30 日間)
Astrid Schiulaz
Astrid Schiulaz 2020 年 6 月 25 日
コメント済み: Astrid Schiulaz 2020 年 6 月 26 日
Hello everybody, I have two arrays of data and I want to write a code for this
I tried
s=symsum( (a(:)-mean(a)).*(b(r+1:n-r)-mean(b)), k, 1, n-r);
but it's not working, I tried using solutions with sum but I get an array as an output and I'm not sure how to do this.

採用された回答

Gaurav Aggarwal
Gaurav Aggarwal 2020 年 6 月 25 日
Hi Astrid,
I am not sure how did you do it using the sum function, I tried it and I am getting a single value as an output and not an array.
I am assuming a and b are meant to be the means of their respective arrays, and that limit of summations go from 1 to n-r
%% (a{i} - a)
first = a(1:n-r) - mean(a);
%% (b{i+r} - b)
second = b(r+1:n) - mean(b);
%%
answer = sum(first .* second);
Let me know if this helps you. Thanks.
  1 件のコメント
Astrid Schiulaz
Astrid Schiulaz 2020 年 6 月 26 日
It worked, I made a mistake with the indexes. Thanks!

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

その他の回答 (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