Convert m file into C++

hello I have some trouble with using Matlab coder
Here is my code. I have tried using Function to generate c++ code, But it was hard to convert.
Could you give me some advise for me to convert this codes into C++?
Should I change it manually?
%%
Larmor= 42.58; % Mhz/T
B0= 2.8944; % T (if ideal, 3T)
Waterppm= 4.7; % To align ppm (NAA~2.01)
Bandwidth= 2000; % sampling rate 1 datapoint per 0.0005s
Numdata= 2048; % common setting
LarmorB0= spec.Larmor*spec.B0; % Mhz
Total_ppm= spec.Bandwidth/spec.LarmorB0; % per ppm (1/M= ppm), approximatley
samplesperppm= round(spec.Numdata/spec.Total_ppm); % samples per ppm
DfStart= 9; % Noise estimated in downfield within 9ppm to 10ppm
DfEnd= 10;
UfStart= 0.5; % 0.5ppm to 4.556ppm (512pts)
UfEnd= 4.556;
%%
obj.strings= ["HG", "Ala", "Asp", "Cr", "GABA", "GPC", "GSH", "Glc", "Gln", "Glu",...
"Lac", "NAA", "NAAG", "PCh", "PCr", "PE", "Tau", "Water", "mI"];
obj.strings_MMindiv= ["MM09", "MM12", "MM14", "MM16", "MM17", "MM18", "MM20", "MM21", "MM23", "MM26",...
"MM30", "MM31", "MM32a", "MM32b", "MM37", "MM38", "MM40"];
obj.strings_MM= ["MM1", "MM2", "MM3", "MM4", "MM5", "MM6", "MM7", "MM8", "MM9"];
%Phantom simulation and "In vivo characterization of the liver fat 1H MR spectrum", Gavin Hamilton
obj.strings_Art= ["Water1", "Ghost1", "Ghost2", "Ghost3", "Ghost4", "Ghost5", "Ghost6", "Ghost7", "Ghost8",...
"Ghost9", "Ghost10", "Ghost11", "Ghost12", "Ghost13", "Ghost14", "Ghost15", "Ghost16",...
"Ghost17", "Ghost18", "Ghost19", "Ghost20", "Lip1", "Lip2", "Lip3", "Lip4", "Lip5", "Lip6"];
% Metabolites
% MetabolitesOnlyFID
% MMbaselineOnlyFID
% Artifacts
% ArtifactsOnlyFID
% Abnormality
%% basis_spec
file_1 = 'Basis_set_2k.txt';
file_2 = 'Basis_set_2k_UpfieldOnly.txt';
N= 100;
opts = detectImportOptions(file_1);
opts.MissingRule= 'omitrow';
data = readcell(file_1,opts); % Load txt data
data(:,3:4)=[]; % Clear the fft data
data= cell2mat(data);
arrdata= complex(data(:,1),data(:,2)); % Combine to tranform to the complex-double dataform
metnum= length(obj.strings);
for i= 1:length(obj.strings)
eval(['' char(obj.strings(i)) '= arrdata(1+2048*(i-1):2048+2048*(i-1));']) % Load metabolites basis
end
%%
amp_met(1,:)= (0-0)*rand(1,N) + 0; %2HG
amp_met(2,:)= (1.5-0.1)*rand(1,N) + 0.1; %Ala
amp_met(3,:)= (2.0-1.0)*rand(1,N) + 1.0; %Asp
amp_met(4,:)= (10.5-4.5)*rand(1,N) + 4.5; %Cr
amp_met(5,:) = (2.0-1.0)*rand(1,N) + 1.0; %GABA
amp_met(6,:) = (2.0-0.5)*rand(1,N) + 0.5; %GPC
amp_met(7,:) = (3.0-1.5)*rand(1,N) + 1.5; %GSH
amp_met(8,:) = (2.0-1.0)*rand(1,N) + 1.0; %Glc
amp_met(9,:) = (6.0-3.0)*rand(1,N) + 3.0; %Gln
amp_met(10,:) = (12.5-6.0)*rand(1,N) + 6.0; %Glu
amp_met(11,:) = (1.0-0.2)*rand(1,N) + 0.2; %Lac
amp_met(12,:) = (17.0-7.5)*rand(1,N) + 7.5; %NAA
amp_met(13,:) = (2.5-0.5)*rand(1,N) + 0.5; %NAAG
amp_met(14,:) = (2.0-0.5)*rand(1,N) + 0.5; %PCh
amp_met(15,:) = (5.5-3.0)*rand(1,N) + 3.0; %PCr
amp_met(16,:) = (2.0-1.0)*rand(1,N) + 1.0; %PE
amp_met(17,:) = (6.0-2.0)*rand(1,N) + 2.0; %Tau
amp_met(18,:) = (0-0)*rand(1,N) + 0; %Water
amp_met(19,:) = (9.0-4.0)*rand(1,N) + 4.0; %mI
VariableNamesCell= cellstr(obj.strings);
obj.Metabolites= cell2table(cell(1,metnum));
obj.Metabolites.Properties.VariableNames= VariableNamesCell;
tmp= cell(1,length(obj.strings));
for i= 1:length(obj.strings)
tmp(i)= {amp_met(i,:)};
end
obj.Metabolites{1,1:length(obj.strings)}=tmp(1:length(obj.strings));
metConcat= [];
for i= 1:length(obj.strings)
eval(['metConcat= [metConcat ' char(obj.strings(i)) '];'])
end
metcombined= metConcat*amp_met;
obj.MetabolitesOnlyFID= metcombined;
%%
%% MMbaseline

1 comentario

Rik
Rik el 3 de Mzo. de 2021
You could start by improving this code in the first place. All those eval calls will make it difficult to convert this into anything useful.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Fourier Analysis and Filtering en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 3 de Mzo. de 2021

Comentada:

Rik
el 3 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by