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

dpb
dpb le 4 Déc 2018

0 votes

disp("\nReading values from 'xxxx3padata.txt' file.....")
val=importdata('xxxx3padata.txt');
Rmn=mean(abs(val));
Rms=rms(val);
Rmnmx=max(val)-min(val);
fprintf('\nThe arithmatic mean value of the measurements is: %f microns\n',Rmn);
fprintf('\nThe root mean square average of the measurements is: %f microns\n',Rms);
fprintf('\nThe maximum roughness height of the measurements is: %f microns\n',Rmnmx);
clear val
Warning: Air code, test well...

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!

Translated by