generated from freudenreichan/info2Praktikum-NeuronalesNetz
getMatrixAt in Matrix.c eingeführt
This commit is contained in:
1 parent
8030e0a27f
commit
fe8088ec40
1 file changed
+11
@@ -50,6 +50,17 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
|||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx){
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx){
|
||||||
|
|
||||||
|
if (rowIdx >= matrix.rows || colIdx >= matrix.cols) { //Gibt fehler bei falschen Idx werten aus / !Arraysyntax beachten, bei 5 rows ist im Array 0 bis 4 deviniert!
|
||||||
|
return UNDEFINED_MATRIX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int memoryspace = 0; //variable für den Eintrag an der gesuchten stelle
|
||||||
|
unsigned int columnlength = matrix.cols; //maximale länge einer Zeile
|
||||||
|
|
||||||
|
memoryspace = (rowIdx * columnlength)+colIdx; //Bsp. Matrix = 5 Spalten und 4 Zeilen. Gesucht ist Zeile 3, Spalte 2. In meinem Eindimensionalen Array ist das 12
|
||||||
|
//(2*4)+2 = 12 /Ich gehe erst die vollen Zeilen durch, dann die Position in der Zeile
|
||||||
|
//!Zeilen und Spalten beginnen bei 0 (Array syntax)!
|
||||||
|
return matrix.space[memoryspace]; //Gibt den Matrixwert an der ausgerechnenten Stelle zurück / ![] für Arraywert!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user