MATLAB: Deleting columns in matrix based on specific looping

loopsmatrix manipulation

Hi,
I could really use some help/advice – I'm a novice when it comes to matlab.
Basically I start off by taking in an NxN matrix and have to cut out certain columns within it to only run a subsection of it through a secondary analysis script.
The matrix (NTot) is made up of average z-scores (from a fisher r to Z transformation, so it starts out as a correlation matrix) coming from two functional brain networks across a few dozen subjects. Let's say the two networks are N1 and N2. Each of these networks are made up of multiple nodes, and each element of the matrix is the z-score of the correlation between the two nodes' time series. Thus, NTot is an (NumNodesN1+NumNodesN2)x(NumNodesN1+NumNodesN2) matrix. What I need the code to do is the following:
1) Open up NTot
2) Remove the first NumNodesN1*(NumNodesN1+NumNodesN2) columns
3) Loop through the following:
a) Retain NumNodesN1 columns
b) Remove NumNodesN2 columns
c) Repeat (a) & (b) until you are left with NumNodesN1*NumNodesN2 columns
- This will represent a section of the NTot matrix (specifically the
bottom left) whereby one only has values representing the z-scores of
N1 to N2's nodes
For example: say I have two networks of interest (N1 & N2)
N1 has 8 nodes, or components, and N2 has 10 nodes/components. Therefore the matrix (NTot) is 18×18. Doing things by hand I would first open NetTot (Step 1, above) remove the first 144 columns (NumNodesN1*(NumNodesN1+NumNodesN2)) – Step 2, above). Then I would retain the next 8 columns (3a) and remove the following 10 columns (3b). I would repeat these steps (3c) until I'm left with an 8×10 matrix that only represents elements pairing N1 and N2's component nodes.
I think that, ideally, I would need a function that does the above and whose input would be NumNodesN1 and NumNodesN2 and whose output would be the manipulated matrix.
Thanks so much for your suggestions!

Best Answer

If Ntot is only 18x18, how are you going to remove 8*18 (=144) columns? Something is inconsistent in your description.
Assuming it's in the overall size being (N1+N2)^2 in each direction (which would be 324 in your example) it would be
N=n1+n2; % shorthand for the total
M=N*(N-n1)/N; % the number of groups of n1+n2 size after first block
ix=[false(1,n1*N,1) repmat([true(1,n1) false(1,n2)],1,M)]; % logical vector of columns to keep
matout=matin(:,ix); % return the selected matrix columns
For your sample of n1=8, n2=10, one finds for a sanity check...
>> N=n1+n2
N =
18
>> N^2
ans =
324
>> M=N*(N-n1)/N
M =
10
>>
>> length(ix)
ans =
324