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;
}

 採用された回答

dpb
dpb 2018 年 12 月 4 日

0 投票

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...

その他の回答 (0 件)

質問済み:

2018 年 12 月 3 日

回答済み:

dpb
2018 年 12 月 4 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by