Home > Back-end >  Turn on the vector storage and read the file
Turn on the vector storage and read the file

Time:09-28

I want to write a program that is about: read two TXT in the data, a series of calculation in the call data, I read this file code can only read a file at a time, is there any way I can read the two documents coexist to vector inside (is part of the originalCoor and targetCoor), and then call? Want to hand in your homework tomorrow, really don't know what to write, help, help changed! Grateful!

# include & lt; Iostream>
# include "Eigen/Dense"
# include & lt; Vector>
# include & lt; Map>
# include & lt; Fstream>
# include & lt; Sstream>

Using namespace STD.
Using the namespace Eigen;

//read the file
Bool readCECFCoor (vector{
The string fileName.//file name
Cout & lt; <"Both Please enter the path \ n";
Cin & gt;> The fileName.

Ifstream file (fileName);
if (! File. The is_open ()) {
Cout & lt; <"Unable to read the file" & lt; return false;
}
The string line;
Vector Strings;
Double X=0.0;
Double Y=0.0;
Double Z=0.0;
Int counter=0;
String name="";
While (getline (file, line))
{
Istringstream iss (line);
Iss & gt;> The line;
String individualInfo="";
for (int i=0; I & lt; The line length (); I++)
{
If (line [I]==', ')
{
Name===0 if (counter) individualInfo;
If (counter==1) X=stod (individualInfo);
If (counter==2) Y=stod (individualInfo);
Cout & lt; Counter++;
IndividualInfo="";
}
The else
{
IndividualInfo=individualInfo + line [I];
}
}
Z=stod (individualInfo);
Cout & lt; CoorECEF_withname tempCoor={X, Y, Z, name};
Result. The push_back (tempCoor);
}
File. The close ();
return true;
}

Four parameters calculated for//
Bool computePara_4 (vector{
VectorVector name;
Int originalCoor_n=originalCoor. The size ();
Int targetCoor_n=targetCoor. The size ();
If (originalCoor_n!=targetCoor_n)
{
Cout & lt; <"The source points coordinate points and the target coordinate system is not equal to! \ n "& lt; return false;
}
If (originalCoor_n * 2-4 & lt; 0)
{
Cout & lt; <"Insufficient condition equation number! Can't solve! \n";
return false;
}

Int d=originalCoor_n;//point number
Int n=para. Precision. N=originalCoor_n * 2;//condition equation number
Para. Precision. R=para. Precision. N - 4;//redundancy
MatrixXd B (n, 4);//matrix
MatrixTheir lives esize (n, 1);
Y_s MatrixXd x_s (d, 1), (d, 1), x_t (d, 1), y_t (d, 1);
for (int i=0; I & lt; d; I++)
{
X_s (I, 0)=originalCoor [I]. X.
Y_s (I, 0)=originalCoor [I] y;
X_t (I, 0)=targetCoor [I]. X.
Y_t (I, 0)=targetCoor [I] y;
}
L & lt; Y_t - y_s;

B & lt; MatrixXd: : Zero (d, 1), MatrixXd: : 'Ones (d, 1), - x_s y_s;
MatrixX=(B.t ranspose () * B). The inverse () * B.t ranspose () * L;//method equation,
Para. Dx=x (0, 0);
Para. Dy=x (1, 0);
Para. R=x (2, 0).
Para. K=x (3, 0).
MatrixXd V (n, 1);

//calculate correct number V
V=- (MatrixXd: : Identity (n, n) - B * (B.t ranspose () * B). The inverse () * B.t ranspose ()) * L;
for (int i=0; I{
CoorECEF_withname temp_e={V (I, 0), V (I + d, 0), 0, the name [I]}.
Para. Precision. E.p ush_back (temp_e);
}
//calculate the sigma0
Para. Precision. Sigma0=((V.t ranspose () * V)/para. Precision. R) (0, 0);
Para. Precision. Sigma0=SQRT (para. Precision. Sigma0);
return true;
}

Int main ()
{
VectorReadCECFCoor (result);
VectorVectorParameter_4 para;
ComputePara_4 (originalCoor targetCoor, para);
String hold;
Cin & gt;> Hold;
return 0;
}

CodePudding user response:

Int main ()
{
VectorReadCECFCoor (result);
ReadCECFCoor (result);//two calls the function, good input different filename ah
Vector CodePudding user response:

reference 1st floor qybao response:
int main ()
{
VectorReadCECFCoor (result);
ReadCECFCoor (result);//two calls the function, good input different filename ah
Vector


I in the subsequent procedure to invoke data in a file, two files are stored in a vector?

CodePudding user response:

You look at the code, to understand the code, the two files in the memory will be saved in the same result (whether save in the same vector is to see your parameters, pass two calls are the same parameters, the result is ok),
  • Related