is it possible to convert c++ code to matlab code?

6 vues (au cours des 30 derniers jours)
SURENTHIRAN C
SURENTHIRAN C le 25 Fév 2014
Commenté : Walter Roberson le 13 Mar 2021
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 commentaires
Malaa Mansour
Malaa Mansour le 21 Août 2020
Modifié(e) : Walter Roberson le 13 Mar 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
Walter Roberson le 13 Mar 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 ?

Connectez-vous pour commenter.

Réponses (2)

Xylo
Xylo le 25 Fév 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 commentaire
KAE
KAE le 13 Juil 2018
Doesn't Coder translate Matlab to C++, not the other way around (C++ to Matlab)?

Connectez-vous pour commenter.


Attaullah Shafiq
Attaullah Shafiq le 13 Mar 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)

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by