generated from freudenreichan/info2Praktikum-NeuronalesNetz
Matrixpart
This commit is contained in:
1 parent
9f3fc14182
commit
5d5a51b805
3 files changed
+66
-16
No files matched your search
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const unsigned int windowWidth = 800;
|
||||
const unsigned int windowWidth = 800; //Fenstergröße
|
||||
const unsigned int windowHeight = 600;
|
||||
|
||||
int exitCode = EXIT_FAILURE;
|
||||
|
||||
+57
-13
@@ -2,34 +2,78 @@
|
||||
#include <string.h>
|
||||
#include "matrix.h"
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
// TODO Matrix-Funktionen implementieren (done)
|
||||
//Matrix Zeilen und Spaltenanzahl festlegen
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
|
||||
Matrix matrix;
|
||||
matrix.rows = rows;
|
||||
matrix.cols = cols;
|
||||
clearMatrix(&matrix);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
//Matrix Speicher leeren
|
||||
void clearMatrix(Matrix *matrix)
|
||||
{
|
||||
|
||||
for (int i=0; i < (*matrix).rows; i++)
|
||||
{
|
||||
for (int j = 0; j < (*matrix).cols; j++)
|
||||
{
|
||||
(*matrix).array[j][i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Matrix Werte setzen
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
|
||||
if (rowIdx < 28 && colIdx < 28)
|
||||
{
|
||||
matrix.array[rowIdx][colIdx] = value;
|
||||
}
|
||||
}
|
||||
|
||||
//Matrix Werte auslesen
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
|
||||
if (rowIdx < 28 && colIdx < 28)
|
||||
{
|
||||
return matrix.array[rowIdx][colIdx];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Matrizen addieren
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
||||
if ((matrix1.rows != matrix2.rows) || (matrix1.cols != matrix2.cols)) //Überprüfung der Addierbarkeit zweier Matrizen
|
||||
{
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < matrix1.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < matrix1.cols; j++)
|
||||
{
|
||||
result.array[i][j] = matrix1.array[i][j] + matrix2.array[i][j];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Matrizen multiplizieren
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Matrix result = createMatrix(matrix1.rows, matrix2.cols);
|
||||
if (matrix1.cols != matrix2.rows) //Überprüfung der Multiplizierbarkeit zweier Matrizen
|
||||
{
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < matrix1.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < matrix2.cols; j++)
|
||||
{
|
||||
for (int k = 0; k < matrix1.cols; k++)
|
||||
{
|
||||
result.array[i][j] += (matrix1.array[i][k] * matrix2.array[k][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
+8
-2
@@ -5,8 +5,14 @@
|
||||
|
||||
typedef float MatrixType;
|
||||
|
||||
// TODO Matrixtyp definieren
|
||||
|
||||
// TODO Matrixtyp definieren (done)
|
||||
typedef struct Matrix
|
||||
{
|
||||
int array[28][28]; //28 x 28 ist die Auflösung jedes Bildes
|
||||
unsigned rows; //Zeilen
|
||||
unsigned cols; //Spalten
|
||||
short truenumber; //zwei Bite Länge am Ende jedes Bildes
|
||||
} Matrix;
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||
void clearMatrix(Matrix *matrix);
|
||||
|
||||
Reference in new issue
Block a user