Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting a lot of errors with this code does anyone have a suggestion? #incl

ID: 3720980 • Letter: I

Question

I am getting a lot of errors with this code does anyone have a suggestion?

#include <iostream>

#include <vector>

#include <fstream>

#include <algorithm>

using namespace std;

int main() {

//Extract data from two txt files and create initial vector

vector<double> Adata;

vector<double> Bdata;

int i = 0;

// get A data into a vector

ifstream in("ecg_1.txt"); // change it to other file name if you want. but make sure you have input.txt to test this program

if (in.is_open()) {

int num;

while (in >> num) { // to read numbers

Adata.push_back(num); // add to vector

}

}

cout << endl;

in.close(); // close file

// get B data into a vector

ifstream aa("ecg_2.txt"); // change it to other file name if you want. but make sure you have input.txt to test this program

if (aa.is_open()) {

int num;

while (aa >> num) { // to read numbers

Bdata.push_back(num); // add to vector

}

}

cout << endl;

aa.close(); // close file

// put data into a 2D ditance matrix

vector<vector<double>> Distance_M;

Distance_M[0][0] = 0;

Distance_M.resize(51, vector<double>(51));

for (int i = 0; i < 50; i++)

{

Distance_M[0][i + 1] = Adata[i];

}

for (int j = 0; j < 50; j++)

{

Distance_M[j + 1][0] = Adata[j];

}

for (int i = 1; i < 50; i++) {

for (int j = 1; j < 50; j++) {

Distance_M[i][j] = abs(Adata[i] - Bdata[j] + min(Distance_M[i - 1][j - 1], Distance_M[i - 1][j], Distance_M[i][j - 1]));

}

}

// Finding the allignment

vector<int> a_points;

vector<int> b_points;

vector<double> allignment;

int l = 50;

int k = 50;

int x = 50;

int y = 50;

while (l > 1 && k > 1)

{

// Minimum point is to the left

if ((Distance_M[x - 1][y] > Distance_M[x - 1][y - 1]) && (Distance_M[x - 1][y] > Distance_M[x][y - 1])) {

int l = l - 1;

int x = x - 1;

a_points.push_back(l);

b_points.push_back(k);

allignment.push_back(Distance_M[x][y]);

// Minimum point is to the down left and right

if ((Distance_M[x - 1][y - 1] > Distance_M[x - 1][y]) && (Distance_M[x - 1][y - 1] > Distance_M[x][y - 1]))

int l = l - 1;

int k = k - 1;

int x = x - 1;

int y = y - 1;

a_points.push_back(l);

b_points.push_back(k);

allignment.push_back(Distance_M[x][y]);

// Minimum point is to the bottom

if ((Distance_M[x][y - 1] > Distance_M[x - 1][y - 1]) && (Distance_M[x][y - 1] > Distance_M[x - 1][y]))

int k = k - 1;

int y = y - 1;

a_points.push_back(l);

b_points.push_back(k);

allignment.push_back(Distance_M[x][y]);

}

// Plot sets A and B

// Plot every allignment

// Will be from a_points to b_points but starting from back so be careful

}

}

Explanation / Answer

#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
//Extract data from two txt files and create initial vector
vector<double> Adata;
vector<double> Bdata;
int i = 0;
// get A data into a vector
ifstream in("ecg_1.txt"); // change it to other file name if you want. but make sure you have input.txt to test this program
if (in.is_open()) {
int num;
while (in >> num) { // to read numbers
Adata.push_back(num); // add to vector
}
}
cout << endl;
in.close(); // close file
// get B data into a vector
ifstream aa("ecg_2.txt"); // change it to other file name if you want. but make sure you have input.txt to test this program
if (aa.is_open()) {
int num;
while (aa >> num) { // to read numbers
Bdata.push_back(num); // add to vector
}
}
cout << endl;
aa.close(); // close file
// put data into a 2D ditance matrix
vector<vector<double> > Distance_M;
Distance_M[0][0] = 0;
Distance_M.resize(51, vector<double>(51));
for (int i = 0; i < 50; i++) {
Distance_M[0][i + 1] = Adata[i];
}
for (int j = 0; j < 50; j++) {
Distance_M[j + 1][0] = Adata[j];
}
for (int i = 1; i < 50; i++) {
for (int j = 1; j < 50; j++) {
Distance_M[i][j] = abs(Adata[i] - Bdata[j] + min(min(Distance_M[i - 1][j - 1], Distance_M[i - 1][j]), Distance_M[i][j - 1]));
}
}
// Finding the allignment
vector<int> a_points;
vector<int> b_points;
vector<double> allignment;
int l = 50;
int k = 50;
int x = 50;
int y = 50;
while (l > 1 && k > 1) {
// Minimum point is to the left
if ((Distance_M[x - 1][y] > Distance_M[x - 1][y - 1]) && (Distance_M[x - 1][y] > Distance_M[x][y - 1])) {
int l = l - 1;
int x = x - 1;
a_points.push_back(l);
b_points.push_back(k);
allignment.push_back(Distance_M[x][y]);
// Minimum point is to the down left and right
if ((Distance_M[x - 1][y - 1] > Distance_M[x - 1][y]) && (Distance_M[x - 1][y - 1] > Distance_M[x][y - 1]))
int l = l - 1;
k = k - 1;
x = x - 1;
y = y - 1;
a_points.push_back(l);
b_points.push_back(k);
allignment.push_back(Distance_M[x][y]);
// Minimum point is to the bottom
if ((Distance_M[x][y - 1] > Distance_M[x - 1][y - 1]) && (Distance_M[x][y - 1] > Distance_M[x - 1][y]))
k = k - 1;
y = y - 1;
a_points.push_back(l);
b_points.push_back(k);
allignment.push_back(Distance_M[x][y]);
}
// Plot sets A and B
// Plot every allignment
// Will be from a_points to b_points but starting from back so be careful
}
}