Deleting columns in matrix based on specific looping

3 views (last 30 days)
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 18x18. 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 8x10 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!

Accepted Answer

dpb
dpb on 23 Jun 2014
Edited: dpb on 23 Jun 2014
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
  3 Comments
dpb
dpb on 23 Jun 2014
Edited: dpb on 23 Jun 2014
Oh, it's my bad on the index expression excepting that it won't work correctly unless it really is a full column you are extracting--which I'm thinking now may not be. I placed the ix column index in the row position inadvertently in the above, it should've been
matout=matin(:,ix); % select ix columns
I've got a meeting; gotta' run. It looks like you've got a mess...how about a small numerical example that can see which actual locations are saving? Meanwhile, I think the basic idea is as presented above if you'll just work out the indexing expressions to the sections you wish. You can use linear addressing into the 2D array to select the values; you just have to be able to write the algebraic relationships between them to generate the proper points.
Paul
Paul on 23 Jun 2014
The switch worked!
Thanks so much for your help.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!