For loop on two different dimensions, nested for loop?
Show older comments
Hi there, I am trying to create a for loop on two different dimensions.
I have testdata, which is a 1 x 7 cell, and within each cell is a X x 23 table.
I would like to conduct a ttest_bonf test between 7 sets of 3 columns of each X x 23 table, and the column indices I specified by creating the 'column' matrix. E.g. test between column 3, 10 and 17, then a test between columns 4, 11, 18, etc.
How can I save the results of the ttest properly? I am not sure how to do this so I have just been throwing the f index in any possible place on the left side. I am new to Matlab
% create a test dataset similar to mine
id = {'one'; 'two' ;'three'; 'four'};
testtable1=[id array2table(rand(4,22))];
testtable2=[id array2table(rand(4,22))];
testtable3=[id array2table(rand(4,22))];
testdata = {testtable1, testtable2,testtable3}; % this is a 1 x 4 cell with a 4 x 23 table within
h= [];
p= [];
n = [3 10 17]; % create matrix of column numbers
column = [n; n+1; n+2; n+3; n+4; n+5; n+6];
for c=1:(size(testdata,2))
for f=1:size(column,1)
[h(c,:),p(c,:)]{f}=ttest_bonf(table2array([testdata{1,c}(:,column(f,1)) testdata{1,c}(:,column(f,2)) testdata{1,c}(:,column(f,3))]));
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!