summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/c/fSum.c
blob: cd9483ad35d401186e7b885228f6b1e553c85b98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/********************************
Author: Sravanthi Kota Venkata
********************************/

#include "sdvbs_common.h"

F2D* fSum(F2D* inMat)
{
    F2D *outMat;
    int rows, cols, i, j, k;
    float temp;
    int newRow, newCols;
    int Rcols;

    rows = inMat->height;
    cols = inMat->width;

    if(cols == 1 || rows == 1)
        Rcols = 1;
    else
        Rcols = cols;

    outMat = fSetArray(1,Rcols,0);

    if( cols == 1)
    {    
        temp = 0;
        for( j=0; j<rows; j++)
            temp = temp + subsref(inMat,j,0);
        asubsref(outMat,0) = temp;
    }
    else if( rows == 1)
    {
        temp = 0;
        for( j=0; j<cols; j++)
            temp = temp + asubsref(inMat,j);
        asubsref(outMat,0) = temp;
    }
    else
    {
        for( i=0; i<cols; i++)
        {
            temp = 0;
            for( j=0; j<rows; j++)
                temp = temp + subsref(inMat,j,i);
            asubsref(outMat,i) = temp;
        }
    }

    return outMat;
}