How to convert Matlab functions to Rstudio?

Asked

Viewed 170 times

0

tempo=Seq;   
conc=NCelTotais;
coef_ini = [MaxCT 1 2]; 
coef=[];
OPTIONS = optimset('MaxIter',1000,'TolFun',0.001,'TolX',0.01);
coef = fminsearch(@funcaoerro_sigmoide,coef_ini,OPTIONS);
A=coef(1);
B=coef(2);
C=coef(3);
y = A*sigmf(tempo, [B C]);
fNCelTotais=y;


where:
**funcaoerro_sigmoide**

function erro = funcao_sigmoide(coef);

global tempo conc;

A=coef(1);
B=coef(2);
C=coef(3);

y = A*sigmf(tempo, [B C]);
erro1 = (conc-y).^2;

erro=sum(erro1);

2 answers

0

TL;DR:

You have to translate by seeing what a code does and implementing in the other language.

More details:

In fact, your question is not very clear, but assuming you need to translate the function you have put up to , There’s not much to do. Maybe there is someone who has something similar in R, but still you need to describe what the function does (it’s the fit error of a function sigmoid).

There is a package CRAN DE R/MATLAB, but it’s just an interface to Matlab, which needs to be installed on the system. I don’t know if it’s compatible with Rstudio.

  • I’ll try to explain it better! I have a set of experimental data that needs to be adjusted by a theoretical curve (e.g. sigmoid) through least squares. In Matlab you have the main program and its corresponding function which calculates by least squares. core program
'tempo=Seq; 
conc=NCelTotais;
coef_ini = [MaxCT 1 2]; 
coef=[];
OPTIONS = optimset('MaxIter',1000,'TolFun',0.001,'TolX',0.01);
coef = fminsearch(@funcaoerro_sigmoide,coef_ini,OPTIONS);
A=coef(1);
B=coef(2);
C=coef(3);
y = A*sigmf(tempo, [B C]); fNCelTotais=y;' subroutine described as function

  • @Marcossalvino In a comment is not the best place to put all this. I recommend making a editing in your question and add relevant information!

-1

I’ll try to explain it better! I have a set of experimental data that needs to be adjusted by a theoretical curve (e.g. sigmoid) through least squares. In Matlab you have the main program and its corresponding function that calculates by least squares. programa principal 'tempo=Seq; conc=NCelTotais; coef_ini = [MaxCT 1 2]; coef=[]; OPTIONS = optimset('MaxIter',1000,'TolFun',0.001,'TolX',0.01); coef = fminsearch(@funcaoerro_sigmoide,coef_ini,OPTIONS); A=coef(1); B=coef(2); C=coef(3); y = A*sigmf(tempo, [B C]); fNCelTotais=y;' subroutine described as function

  • Edit your question, don’t add an answer that doesn’t answer your question.

  • If you have any questions, [tour] and [help] can help you with how to edit.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.