Is this possible?

I wanted to make sure that this was possible to do in MATLAB and possibly how I would do it.
I have an array of 100 random binary, undirected matrices that I've calculated. I need to find the average overlap between these matrices. I know how to do this conceptually but not in code: add two matrices, where there is a 2, there is an overlap, do this for all comparisons and average.
However, I have no idea how to do this in code or if it's even possible.

 Accepted Answer

overlaps = a & b;
average_overlap = mean(overlaps(:)); %under one definition

4 Comments

Timothy
Timothy on 4 May 2012
This worked to find the overlap. Now my only issue is that I want to loop this since there are 100 entries in each array (and 6 arrays total). What is the syntax for moving through an array? is there something like a recordset.movenext command?
What do you mean by "move through the array" ? The average_overlap variable I show being calculated is a calculation over the entire array, since that was your question "the average overlap between these matrices". Do you need a row by row calculation? If so then
average_overlap = mean(overlaps,2);
Or do you have cell arrays of matrices? Or 3 dimensional matrices where the third dimension is matrix number? Is pairwise overlap between every one of the 100*99/2 pairs to be calculated?
Timothy
Timothy on 5 May 2012
It is a cell array of matrices. This is what I want to do:
One cell array of matrices (random networks)
One "experimental" matrix
I need to compare the experimental matrix to each of the matrices in the random networks cell array for overlap. I need to count how many overlaps there are in each comparison and then average these. I have no idea how to do this as I only know VBA and this is my first time using MATLAB.
for J = 1 : length(TheNetworksCellArray)
overlaps = TheNetworksCellArray{J} & ExperimentalMatrix;
average_overlap(K) = mean(overlaps(:));
end

Sign in to comment.

More Answers (1)

Timothy
Timothy on 5 May 2012

0 votes

i mentioned this in the comments but is there a way to loop through these comparisons instead of doing it by hand? I have one matrix that I need to compare for overlap to 100 random matrices currently in a cell array. If possible, I'd also like to have the loop count the number of overlaps in each(this is the only important number I need) comparison.
i've tried a few things like for a = cellarray{1,1:1,100} but these obviously haven't worked so far.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!