フィルターのクリア

Correlate through each matrix row

3 ビュー (過去 30 日間)
Elizabeth Yeap
Elizabeth Yeap 2020 年 3 月 7 日
回答済み: Ameer Hamza 2020 年 3 月 7 日
Hello,
I have the following matrix double_new_WB_prop = [12 74000]. What I want to do is;
  1. Correlate a specific row with 3700 columns with another specific row with 3700 columns.
  2. Repeat for all 12 rows.
% Correlate each row of a variable with rows of another variable
[rows,cols] = size(double_new_WB_prop);
ET_GWP = [];
for j = 1:rows
ET_GWP = corr(double_new_WB_prop(j,1:3700), double_new_WB_prop(j,70301:74000));
end
My problem is that ET_GWP is returning all NAN (not suppose to return this). My code also shows no error.
I don't know where I'm going wrong and it would helpful if someone could point out what I'm doing wrong.
Thank you.

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 7 日
Since you are trying to find the correlation between two one dimensional vectors, you should use corrcoef instead of corr.
Also, the value of ET_GWP is discarded in each iteration. One solution is to create a cell array to save all values.
% Correlate each row of a variable with rows of another variable
[rows,cols] = size(double_new_WB_prop);
ET_GWP = [];
for j = 1:rows
ET_GWP{j} = corrcoef(double_new_WB_prop(j,1:3700), double_new_WB_prop(j,70301:74000)');
end

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by