is it possible to convert c++ code to matlab code?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Malaa Mansour
el 21 de Ag. de 2020
Editada: Walter Roberson
el 13 de Mzo. de 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
el 13 de Mzo. de 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 ?
Respuestas (2)
Xylo
el 25 de Feb. de 2014
yes you can! I am not going to ellaborate the whole process. you jst go on this link and you'll get soplution............. better y follow this link:-----------
1 comentario
KAE
el 13 de Jul. de 2018
Doesn't Coder translate Matlab to C++, not the other way around (C++ to Matlab)?
Attaullah Shafiq
el 13 de Mzo. de 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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!