How to compare columns from two data sets in a loop

조회 수: 4 (최근 30일)
Tomaszzz
Tomaszzz 2022년 3월 10일
답변: Sourabh 2025년 1월 24일
Hi all,
I want to compare columns from two data sets in a loop using the ICC function. Is there a way to simplify what I am doing below?
%Import csv file with data
sq_dot1 = importfile('sq_dot1.csv');
sq_dot2 = importfile('sq_dot2.csv');
% variable 1
var1=[sq_dot1(:,1),sq_dot2(:,1)];
[var1_r, var1_LB, var1_UB, var1_F, var1_df1, var1_df2, var1_p]=ICC(var1,'C-k',0.05,0.5);
var1_SD= std(var1(:,1)) + std(var1(:,2))/2;
SEM_var1=var1_SD*sqrt(1-var1_r);
% variable 2
var1=[sq_dot1(:,2),sq_dot2(:,2)];
[var2_r, var2_LB, var2_UB, var2_F, var2_df1, var2_df2, var2_p]=ICC(var2,'C-k',0.05,0.5);
var2_SD= std(var2(:,1)) + std(var2(:,2))/2;
SEM_var2=var2_SD*sqrt(1-var2_r);
% repeat for remaining 52 variables
%save results as a table with rows as variables
row1 = var1
row2 = var 2
row3 = var 3 etc
% and column headers as outcomes
r, LB, UB, F, df1, df2, p, SEM
  댓글 수: 2
KSSV
KSSV 2022년 3월 10일
What is ICC? What it does?
Tomaszzz
Tomaszzz 2022년 3월 10일
편집: Tomaszzz 2022년 3월 10일
@KSSVThanks. interclass corrleation coefficient; describes how strongly units in the same group resemble each other; so in this case how strongly q_dot1(:,1) resembles sq_dot2(:,1).

댓글을 달려면 로그인하십시오.

답변 (1개)

Sourabh
Sourabh 2025년 1월 24일
The most efficient way to perform the comparison would be to use a “for” loop to iterate over the number of variables.
Within the "for" loop, extract the corresponding data for each column from the two datasets. Then, calculate the Intraclass Correlation Coefficient (ICC), Standard Deviation (SD), and Standard Error of Measurement (SEM). Additionally, save the results for each variable into a "table" with preallocated space.
Preallocation improves performance by avoiding dynamic resizing during the loop, which can be computationally expensive.
For more information on “for” loop, please refer the following documentation:
For information on how to create a “table” with preallocated space and store results in it, kindly refer the following documentation:

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by