generated from freudenreichan/info2Praktikum-NeuronalesNetz
Finished Matrix add Function Completing the Set Get Add Branch
This commit is contained in:
parent
9eba090e45
commit
abe4ecec65
19
matrix.c
19
matrix.c
@ -46,7 +46,24 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Matrix MatrixErgebnis = createMatrix(matrix1.rows, matrix1.cols); //Creating Result Matrix
|
||||
if(matrix1.cols != matrix2.cols || matrix1.rows != matrix2.rows){
|
||||
printf("Matrix dimensions do not match\n"); //Error Message if dimensions of Input Matrixes are not identical
|
||||
MatrixErgebnis = clearMatrix(MatrixErgebnis);
|
||||
return MatrixErgebnis;
|
||||
}
|
||||
else{
|
||||
|
||||
for (unsigned int i = 0; i < matrix1.rows; i++){
|
||||
for (unsigned int j = 0; j < matrix1.cols; j++){
|
||||
//Adding Matrix Elements of same row and col index together and store in new Matrix
|
||||
MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return MatrixErgebnis;
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user