From b9b4d926f5c2dfe2979c21e04ba3047608624551 Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Wed, 12 Nov 2025 12:40:02 +0100 Subject: [PATCH 1/3] Started working on Set and Get Function --- matrix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/matrix.c b/matrix.c index 59fd963..798ac2c 100644 --- a/matrix.c +++ b/matrix.c @@ -23,12 +23,14 @@ void clearMatrix(Matrix *matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + matrix = {rowIdx, colIdx, value}; //Writes Value of value variable in the selected place in Matrix + printf("Test: Value at %d, %d : %d\n", rowIdx, colIdx, matrix.buffer[rowIdx][colIdx]); } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + value = matrix.buffer[rowIdx][colIdx]; //Stores value of selected place in Matrix in value variable + return value; } Matrix add(const Matrix matrix1, const Matrix matrix2) From 9eba090e45d4765bb025fb7c7a8e5ced52f74cf4 Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Fri, 14 Nov 2025 16:43:17 +0100 Subject: [PATCH 2/3] Finished Set and Get Functions --- matrix.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/matrix.c b/matrix.c index 798ac2c..a60e891 100644 --- a/matrix.c +++ b/matrix.c @@ -23,15 +23,26 @@ void clearMatrix(Matrix *matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - matrix = {rowIdx, colIdx, value}; //Writes Value of value variable in the selected place in Matrix - printf("Test: Value at %d, %d : %d\n", rowIdx, colIdx, matrix.buffer[rowIdx][colIdx]); + if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ + printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix +} + else{ + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix +} } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - value = matrix.buffer[rowIdx][colIdx]; //Stores value of selected place in Matrix in value variable - return value; + if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ + printf("Index out of bounds\n"); + return 0; + } + else{ + + MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable + return value; } + } Matrix add(const Matrix matrix1, const Matrix matrix2) { From abe4ecec657eece9b9436faa1ebd47419afbe64f Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Mon, 17 Nov 2025 10:04:39 +0100 Subject: [PATCH 3/3] Finished Matrix add Function Completing the Set Get Add Branch --- matrix.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index a60e891..efef3e9 100644 --- a/matrix.c +++ b/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)