Clear Filters
Clear Filters

Need to create a 3 dimensional matrix of subjects, block numbers and 6 sub condition values within each block.

4 views (last 30 days)
Hi, Until now I have worked only with 2D matrices which resemble spreadsheets. Now I have data with one more dimension. I have 19 subjects who each did 8 blocks of an experiment. In each block they got different numbers of task 1 to 6 correct.
Here is the script so far:
clear
close all
subno={'s_01','s_03', 's_05', 's_06', 's_09', 's_11', 's_13', 's_16', 's_18', 's_20', 's_22','s_23', 's_26','s_28', 's_31', 's_33', 's_34','s_35', 's_37',};
blockno={'_01', '_02','_03', '_04', '_05', '_06','_07', '_08'};
for k=1:length(subno)
%defining paths
MAIN = '/data/janani/EoA/logfiles';
PATHIN=[MAIN, '/',subno{k}, '/'];
PATHOUT=[MAIN, '/BEHanalysis/'];
for j=1:length (blockno)
textfile= ['jad1_',subno{k}, blockno{j}, '.txt'];
cd (PATHIN);
list1=dir('*.txt');
fname=[PATHIN, textfile];
fid=fopen(fname);
for i=1:72
[M1(i,:)]=fscanf(fid,'%i', [1 6]);
end
%We write the following loops to extract the correct responses into corr_H0, 1 and 2
%the below loop checks if there is 0, 1 and 2 in both the nuhBIG Hs (2) and resp column (4)
count0=1;
for p = 1:size (M1, 1)
if (M1 (p, 2)==0 && M1 (p, 4)==0)
corr_H0(count0)=p
count0=count0+1;
end
end
count1=1;
for q = 1:size (M1, 1)
if (M1 (q, 2)==1 && M1 (q, 4)==1)
corr_H1(count1)=q
count1=count1+1;
end
end
count2=1;
for r = 1:size (M1, 1)
if (M1 (r, 2)==2 && M1 (r, 4)==2)
corr_H2(count2)=r
count2=count2+1;
end
end
%the below loop checks if there is 0, 1 and 2 in both the nuhSmall Hs (3) and resp column (4)
count0s=1;
for p = 1:size (M1, 1)
if (M1 (p, 3)==0 && M1 (p, 4)==0)
corr_H0(count0s)=p
count0s=count0s+1;
end
end
count1s=1;
for q = 1:size (M1, 1)
if (M1 (q, 3)==1 && M1 (q, 4)==1)
corr_H1(count1s)=q
count1s=count1s+1;
end
end
count2s=1;
for r = 1:size (M1, 1)
if (M1 (r, 3)==2 && M1 (r, 4)==2)
corr_H2(count2s)=r
count2s=count2s+1;
end
end
c= [count0, count1, count2, count0s, count1s, count2s]; %is the array of the 6 values that need to join the j and k values.
%I tried this:
SBC=(k, j, c);
%but it doesn´t give me what I want.
end
end
Just before the end of the loop I would need to input count0, count1, count2, count0s, count1s, and count2s into the matrix which also indicates k (the subject number) and j (which indicates block number) into the matrix before their values are overwritten.
Any help would be appreciated. Thanks! Jan

Accepted Answer

Jarrod Rivituso
Jarrod Rivituso on 15 Jun 2012
Is there a reason you want to store things in a 3-dimensional array? Seems you might be better off, at least at first, keeping things in a structure. For clarity, that would mean replacing the line
subject(k).block(j).count0 = count0;
subject(k).block(j).count1 = count1;
subject(k).block(j).count2 = count2;
subject(k).block(j).count0s = count0s;
subject(k).block(j).count1s = count1s;
subject(k).block(j).count2s = count2s;
To me, this is a bit clearer. The 3-D array approach would be something like
sbc(k,j,1:6) = c;
If you go that route, don't forget to preallocate!
Best of luck!
  1 Comment
Jan
Jan on 18 Jun 2012
The reason was to be able to export it into a spreadsheet and put it through statistical analysis for which I use dlmwrite because I am working with Linux and despite changes, xlswrite doesn´t work here. Do you happen to know how to put a path to the dlmwrite?
Thanks for your help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!