Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Transfer and execute function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello Matlab users,
I want to store the values for a function in the first lines. Is possible to save the function in the main script?
Otherwise is it possible to transfer the function info from the main-script into the fuction-file via variables?
for example: function file starts left_side_of_equation right_side_of_equation unknown variables... function file ends
main-script starts function diff = fit_biexp(x,TR,Y,time_stamps) %start unknown variable A=x(1); B=x(2); T1=x(3); %end unkown variable
diff = sum(((rechte_part_of_equation))-left_part_of_equation).^2); end main-script starts
If it is possible, how? I already tried various ways without success.
Thanks, Chris
0 comentarios
Respuestas (1)
Iain
el 1 de Oct. de 2014
I don't quite get what you're asking:
Are you saying that you want to use a variable function for something? In which case you should be able to use anonymous functions. For example:
my_function = @(x,y)(sin(x)*3 + cos(x)*4 + sin(y)*3 + cos(y)*4);
a = [0 1 2], b = [1; 2; 3; 4], c = bsxfun(my_function,a,b)
Or are you asking for multiple outputs from a function? You can do that by defining a function like this:
function [output1 output2 varargout] = my_function(a,b,c)
output1= a*b*c;
output2 = a^b^c;
if nargout > 2
varargout{1} = c - b - a;
if nargout > 3
varargout{2} = c - b - a;
end
end
You can then call your function as normal: [out1 out2 optional1 optional2] = my_function(1,2,3)
1 comentario
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!