When returning a qvector, the contents of the qvector are lost.
-
QVector<QVector<double>> RegressionClass::PolyRegCoeff(QVector<QVector<double>> x, int M, bool varZero) { int varStart = 0; if (varZero) { varStart = 1; } int rA = x[0].count(); int N = x[0].count(); QVector<QVector<double>> matSquaredX(N, QVector<double>(M+1-varStart)); /* estimated polynomial regression coefficients 계산 */ for (int i = 0; i < N; i++) { for (int j = varStart; j < M + 1; j++) matSquaredX[i][j - varStart] = pow(x[i][0], j); } return matSquaredX; }
I have code like this. When I try to return matSquaredX, size is 0.
In the for statement, the size of matSquaredX was three. -
@IknowQT said in When returning a qvector, the contents of the qvector are lost.:
QVector<QVector<double>>* get_newX() { return m_newX; }; QVector<QVector<double>>* get_newY() { return m_newY; }; Pa->get_newX()[i][0] = X[i][0]; Pa->get_newY()[i][0] = Y[i][0];
If I read right your code,
Pa->get_newX()
andPa->get_newY()
returns a pointer!Should be:
(*Pa->get_newX())[i][0] = X[i][0]; (*Pa->get_newY())[i][0] = Y[i][0];
But looks ugly to me, I would work with references or add some more helper functions, like
setX()
/setY()
-
Hi,
How did you determine that size ?
Did you check the value of matSquaredX before the return statement ? -
my mistake. I solved it.
I have one more question.QVector<QVector<double>>* get_newX() { return m_newX; }; QVector<QVector<double>>* get_newY() { return m_newY; }; Pa->get_newX()[i][0] = X[i][0]; Pa->get_newY()[i][0] = Y[i][0];
c2679 error occurs.
Is there a way to enter a value by substituting?
If you don't declare it as a pointer, your code will work normally. -
@IknowQT said in When returning a qvector, the contents of the qvector are lost.:
c2679
Can you please post the actual errror message?
Instead of returning a pointer to a member you can also return a reference.
-
@IknowQT said in When returning a qvector, the contents of the qvector are lost.:
QVector<QVector<double>>* get_newX() { return m_newX; }; QVector<QVector<double>>* get_newY() { return m_newY; }; Pa->get_newX()[i][0] = X[i][0]; Pa->get_newY()[i][0] = Y[i][0];
If I read right your code,
Pa->get_newX()
andPa->get_newY()
returns a pointer!Should be:
(*Pa->get_newX())[i][0] = X[i][0]; (*Pa->get_newY())[i][0] = Y[i][0];
But looks ugly to me, I would work with references or add some more helper functions, like
setX()
/setY()