Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Transfer and execute function
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Iain
2014년 10월 1일
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
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!