# Subtracting Values in a cell with respect to results from nchoosek?

1 view (last 30 days)
Sim on 18 Oct 2012
Suppose I hav an array a which are basically indices of some values
a = [1 2 3]
b = nchoosek(a,2)
c= size(b)
d = cell(c)
b =
1 2
1 3
2 3
c =
3 2
d =
[] []
[] []
[] []
Now in this cell d, I want to put some values. I have a another cell say newCell (1xn) (here n is always same length as a) which contains double
newCell =
[12737x1 double] [47712x1 double] [6514x1 double]
so i want to have
d = [12737x1 double] [47712x1 double]
[12737x1 double] [6514x1 double]
[47712x1 double] [6514x1 double]
What I want to do in the end is sbutract each values from newCell but with respect to the nchoosek results. Because [12737x1 double] is values for 1
[47712x1 double] is values for 2
[6514x1 double] is values for 3
I am aware we can subtract the values only if the length is same. SO that is where I am stuck. I don no how to go further with this. So I will have to have a if condition for checking if length is same, If it is then it should subtract the values and answer should be zero. If it not same then it should not subtract the values. Say For example:
newCell =
[12737x1 double] [12737x1 double] [6514x1 double]
now d should be
d = [12737x1 double] [12737x1 double]
[12737x1 double] [6514x1 double]
[12737x1 double] [6514x1 double]
It should now check if length is same, then subtract 1st row and store [1 2]in an array keepin in mind that 1 2 are the indices from a. This I want to do for over 150k files. Is there a solution to this. I just have an idea but do not no how to go further with is. Thanks in advance.
Matt J on 18 Oct 2012
I assume you mean d instead of newCell. You should do it as you've written it.

Sean de Wolski on 18 Oct 2012
You could use gsubtract if you have the Neural Networks Toolbox. Else just use a for-loop which is what I would recommend doing anyway.