Obtain rho and pval values from a loop of data measurements

1 回表示 (過去 30 日間)
CB
CB 2022 年 3 月 10 日
コメント済み: CB 2022 年 3 月 10 日
Obtain rho and pha values from a loop of data analysis,
I have created a loop to open multiple spreadsheets from different sources pertaining to collected data measurements (diameter and height) and want to obtain Pearson’s rho and pval values after each iteration for each project in a table.
% Nº of projects
n=20;
% Rango diam boxplots(mm)
rango=5;
for i=1:n
%: Readtable project spreadhseets
if i==1
rawTable = readtable('Project 1,'Sheet','ExportResult');
elseif i==2
rawTable = readtable('Project 2','Sheet','ExportResult');
--------------------------------------------------------------------------------------------------------------------------------------------------
else
rawTable = readtable('Project 2','Sheet','ExportResult');
end
x = rawtable.x; %: Column x
y = rawtable.y; %: Column y
% Pearson (preallocating required.%
[rho(i),pval(i)] = corr(x, y, 'type', 'Pearson');
end
The issue that I have is that I have a pop-up message saying that variable ‘I’ changes in size after each iteration and to consider pre-allocating for speed.
I would wish to obtain a n x 2 column (rho and pval) set of data to enable later data analysis without this issue being flagged up in Matlab and to speed the data processing.
Please, note that I have unsuccessfully tried many different combinations looking at support doc and community.
Any help on this will be appreciated.
Thanks.
Cesar

採用された回答

VBBV
VBBV 2022 年 3 月 10 日
編集済み: VBBV 2022 年 3 月 10 日
[rho(i,:),pval(i,:)] = corr(x, y, 'type', 'Pearson');
  3 件のコメント
Simon Chan
Simon Chan 2022 年 3 月 10 日
Initialize the variables before the for loop.
rho = zeros(n,1);
rho2 = zeros(n,1);
%.....
CB
CB 2022 年 3 月 10 日
Hi Simon,
Thank you so much!
Kind regards,
Cesar

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by