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

9 ビュー (過去 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 Center および File ExchangeMATLAB Coder についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by