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

조회 수: 5 (최근 30일)
SURENTHIRAN C
SURENTHIRAN C 2014년 2월 25일
댓글: Walter Roberson 2021년 3월 13일
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
Malaa Mansour
Malaa Mansour 2020년 8월 21일
편집: Walter Roberson 2021년 3월 13일
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 2021년 3월 13일
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 ?

댓글을 달려면 로그인하십시오.

답변 (2개)

Xylo
Xylo 2014년 2월 25일
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
KAE
KAE 2018년 7월 13일
Doesn't Coder translate Matlab to C++, not the other way around (C++ to Matlab)?

댓글을 달려면 로그인하십시오.


Attaullah Shafiq
Attaullah Shafiq 2021년 3월 13일
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)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by