call the output of matrix in the void function

..
Last edited on
Mat[][] doesn't make sense, sorry. Aside from it not being valid syntax, your Mat function doesn't return anything. It just prints things.

You have to call your Mat function like any other function, something like

1
2
std::vector<std::vector<int>> result;
Mat(result, nbits); // or my_ham_object.Mat(result, nbits); if outside of a class 


To multiple a matrix (represented by a 2d std::vector) by a column vector (represented by a 1d std::vector), you have to manually do the multiplies yourself with for loops.

If you want to be fancy, you could define an operator overload.
1
2
3
4
5
6
std::vector<int> operator*(const std::vector<std::vector<int>>& matrix, const std::vector<int>& column_vector)
{
    std::vector<int> result(column_vector.size());
    /// ...
    return result;
}
Last edited on
I think you can bum std::inner_product to do the legwork. Maybe. Its getting late here.
..
Last edited on
... wrote long reply, closed tab ...


What does Mat[][] mean?

What would Mat[row] mean?
What would Mat[row][col] mean?

( size_t row {}; size_t col {}; )
could you please explain more?
I'm sorry, I don't understand what you're actually asking at this point. I assume it's still not compiling?

You changed
for (int a = 0; a < 3; a++) {
to
for (const auto& row : Mat) {,
but you're still trying to use a variable that no longer exists, called "a".

If you need to keep track of the index, I don't suggest using a for-each loop.
I assume there's 3 rows? As in, Mat.size() == 3? Your use of magic numbers is a bit confusing.

1
2
3
4
5
6
7
8
9
10
	char synd[3];
	
	for (int a = 0; a < Mat.size(); a++) {
		auto& row = Mat[a];
		char result = 0;
		for (int b = 0; b < 7; b++) {
			result += (row[b] * decode[b]);
		}
		synd[a] = result % 2;
	}
hh
Last edited on
The common link that you are trying to glue between your two functions is a connection to your std::vector<std::vector<int>>& result.

I am assuming that when you first call your Mat function, you have an object of type std::vector<std::vector<int>> that is then correctly filled with appropriate values in a 2D way.

But now... your Decode function has no idea what your result matrix is. I never see where you declare an std::vector<std::vector<int>> object to actual use. This design is confusing. Should your Ham class contain a matrix?

If you need to pass in your matrix, then you need to either have it be a member of your Ham class, or you need to pass it in through the Decode function's parameters, like you did with your Mat function.

Perhaps (I'm guessing) something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void Ham::Decode(const std::vector<std::vector<int>>& matrix,
                 std::vector<double> &codedVector, std::vector<int> &decodedVector)
{
	std::cout << "Decode" << std::endl;
	int decode[7];
	
	for (int bits = 0; bits < 7; bits++) {
		if (codedVector[bits] < (voltage / 4)) { decode[bits] = 0; }
		else { decode[bits] = 1; }
	}
	char synd[3];
	
	for (int a = 0; a < 3; a++) {
		char result = 0;
		for (int b = 0; b < 7; b++) {
			result += (matrix[a][b] * decode[b]);
		}
		synd[a] = result % 2;
	}
	// ...
}


Hope that helps.
Last edited on
Topic archived. No new replies allowed.