Converting C++ to Matlab code!
Show older comments
Can anyone be able to help me convert the C++ code below to Matlab code???
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<cmath>
using namespace std;
int main() {
double *val = new double[56];
cout << "\nReading values from 'xxxx3padata.txt' file.....\n";
ifstream input;
input.open("xxxx3padata.txt");
if (!input) {
cout << "\nError! cannot open file";
exit(0);
}
for (int i = 0; i < 56; i++)
input >> val[i];
input.close();
double Ra = 0, Rq = 0, Rm = 0, max = 0, min = 0;
for (int i = 0; i < 56; i++) {
if (val[i] < min)
min = val[i];
if (val[i] > max)
max = val[i];
Ra += fabs(val[i]);
Rq += pow(val[i], 2);
}
Rm = max - min;
cout << "\nThe arithmatic mean value of the measurements is: " << Ra / 56 << " microns\n";
cout << "\nThe root mean square average of the measurements is: " << sqrt(Rq / 56) << " microns\n";
cout << "\nThe maximum roughness height of the measurements is: " << Rm << " microns\n";
delete []val;
return 0;
}
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!