Hi everyone,
I want to concatenate the arrays from 4 files, (each corresponding to a block in a task) for every subject in a list. Each file has 5 variables of interest with 60 rows. I combine them to create a 60×5 array for every block.
I want to concatenate the 4 arrays, to create a single 240×5 array. I repeat this for another phase, where I am trying to generate an output of the same dimensions.
Then, I would like to store these arrays inside cells, to create a Nx3 cell array (N= subjects) with the first column being the ID, then the first phase 240×5 array and then the second phase 240×5 array.
The problem I have right now is that my loop keeps parsing arrays in every cell, so in {2,2} I have a 480×5, in {3,2} a 720×5 and so on.
I know that probably it has something to do with the general organization of my loops, but I am struggling finding the right arrange. Could you please guide me on how to fix this issue? I hope my explanation is clear, otherwise let me know.
Best, Ramiro
%%Empty matrices to populate with results
matLenght = lastID-20;respMat = cell(matLenght,3);lrnMatrix = zeros(0,5);expMatrix = zeros(0,5);%%Loop through each file to get weights
for k = firstID:lastID adjustedPosition = k-20; subject = num2str(k); for kk = 1:4 block = num2str(kk); lrnFile = [subject '_LP_Block' block '.mat']; fileDir = fullfile(dataDir, lrnFile); load (fileDir) trials = 60; location = trials*block; lrnData = horzcat(dE.leftWeight, dE.rightWeight, dE.timeTrial, dE.keyResp, dE.bestDecision); lrnMatrix = vertcat(lrnMatrix, lrnData); end for kk = 1:4 block = num2str(kk); expFile = [subject '_EP_Block' block '.mat']; fileDir = fullfile(dataDir, expFile); load (fileDir) trials = 60; location = trials*block; expData = horzcat(dE.leftWeight, dE.rightWeight, dE.timeTrial, dE.keyResp, dE.bestDecision); expMatrix = vertcat(expMatrix, expData); end %%Insert subject ID in the first column of the array
respMat{adjustedPosition,1} = k; respMat{adjustedPosition,2} = lrnMatrix; respMat{adjustedPosition,3} = expMatrix; end
Best Answer