is it possible to convert c++ code to matlab code?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i have written my project concept in c++ language just i want to convert c++ to matlab code it is possible give me suggestions or is c++ code work in matlab software pls help me
2 Kommentare
Malaa Mansour
am 21 Aug. 2020
Bearbeitet: Walter Roberson
am 13 Mär. 2021
clc;
clear all;
close all;
fprintf(' Problem 1.1 \n');
mu1 = 2;
mu2 = -1;
sigma1 = sqrt(4);
sigma2 = sigma1;
r = (2+-1)/2;
p1 = 1-normcdf(r,mu1,sigma1)
%prob. of reception of 2 given 2 was trasmitted
p2 = 1-normcdf(r,mu2,sigma2)
%prob.of reception of 2 given -1 was trasmitted
P = 0.5*(p1+p2);
fprintf('\n The probability of decision of 2, theoretically,is : %4.3f \n',P);
x = rand(1,10000);
% Generation of -1 & +2
for i=1:length(x)
if( x(i)>0.5)
x(i)=2;
else
x(i)=-1;
end
end
std =sqrt(4);
% standard-deviation of noise
n = std*randn(size(x));
y = x + n;
% received signal
n_of_2 =0 ;
% initialization of the counter;
x_hat = [];
% recovered signal
for j =1:length(y)
if ( y(j) > 0.1 )
% Decision making
x_hat(j)=2;
n_of_2=n_of_2+1;
else
x_hat(j)=-1;
end
end
fprintf(' The probability of decision of 2 is : %4.3f \n',n_of_2/ length(x));
% Problem 2
% To compute Prob. of error
fprintf(' The probability of error, theoretically, is : %4.3f \n',0.5*(p1-p2));
e = x-x_hat;
n_error = nnz(e);
1
fprintf(' The probability of error is : %4.3f \n',n_error/length(x));
Problem 1.1
p1 = 0.7734
p2 = 0.2266
Walter Roberson
am 13 Mär. 2021
I reformatted your code for you, as it was unreadable.
Why do you have the "1" by itself after calculating n_error ?
Why do you have the line
Problem 1.1
which will attempt to invoke a function named Problem with character vector input '1.1' ?
What does this have to do with the Question about converting C++ code to MATLAB ?
Antworten (2)
Attaullah Shafiq
am 13 Mär. 2021
create a MEX file via MATLAB Coder (using MATLAB Coder on a simple M file that just calls the C++ function using coder.cinclude and coder.ceval)
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!