How can i fill a pre-allocated matrix 2D?

2 ビュー (過去 30 日間)
Harry Smith
Harry Smith 2021 年 7 月 25 日
コメント済み: Image Analyst 2021 年 7 月 25 日
Hello everyone!
i hope you can help me.
My code is:
[A, B]=size(storage);
nan_matrix=NaN(500,1000);
for ii=1:A
for k=1:B
[x,y]=corr(....)
end
end
%put x-values in the nan_matrix and save this matrix
How?
  6 件のコメント
Harry Smith
Harry Smith 2021 年 7 月 25 日
For example:
[rho, p_val]=corr(x,y, 'type', 'spearman');
the x_dimension is: 300x4
So I preallocated a matrix:
nan_matrix=NaN(500,1000);
in which to store the various rho, otherwise every time the loop restarts for the next column of x, the results will be overwritten.
I can't figure out how to store the results in the pre-allocated matrix before the cycle restarts.
I can do this with an empty vector:
example:
[A, B]=size(storage);
empty_vector=[];
for ii=1:A
for k=1:B
[x,y]=corr(....)
empty_vecto=[empty_vector; x]
end
end
but not with a nan matrix of a particular size
dpb
dpb 2021 年 7 月 25 日
[rho, p_val]=corr(x,y, 'type', 'spearman');
the x_dimension is: 300x4
So, what is y?
"If you input matrices X and Y, rho is a k1-by-k2 matrix, where k1 and k2 are the number of columns in X and Y, respectively. The entry rho(a,b) is the pairwise linear correlation coefficient between column a in X and column b in Y."
I still don't follow why you think you need other storage...

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

回答 (1 件)

Image Analyst
Image Analyst 2021 年 7 月 25 日
I'd use xcorr2().
  2 件のコメント
Harry Smith
Harry Smith 2021 年 7 月 25 日
? sorry, I am not an expert in matlab
Image Analyst
Image Analyst 2021 年 7 月 25 日
It's a sliding window that gives you the correlation of one set of data with another. What were you thinking of doing when you had corr() inside the double nested for loop?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by