Converting C++ to Matlab code!
Afficher commentaires plus anciens
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;
}
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!