0

I have such a matlab function:

function j = globalfun(a, xr, x)

        gv_0 = 0;
        gv_1 = 0;

        counter1_0 = 0;
        counter1_1 = 0;
        counter2_0 = 0;
        counter2_1 = 0;
        counter3_0 = 0;
        counter3_1 = 0;
        counter4_0 = 0;
        counter4_1 = 0;
        ............................................
        ............................................
        score = gv_0/gv_1;
end

I haven't written all the function codes, because it is not needed.

The question is, I need to get "score" value from another script I'm using.

How can I manage the issue?

Thanks,

6
  • 1
    What is a score value? Or if you want to return the value "score" from the function? Commented Mar 8, 2015 at 14:58
  • score is a value calculated inside of the algorithm. Commented Mar 8, 2015 at 14:59
  • 2
    If you need score somewhere else, return it: function [j,score] = globalfun(a, xr, x) Commented Mar 8, 2015 at 15:00
  • 1
    So, do you want to return the value "score" from your function? Commented Mar 8, 2015 at 15:00
  • yes, exactly. When I run the code, I get the error "too many input arguments." Commented Mar 8, 2015 at 15:01

1 Answer 1

2

I assume you copy-pasted the function syntax from somewhere and that you don't need to return j. Define this function in globalfun.m

function score = globalfun(a, xr, x)
    ...
    score = gv_0/gv_1;
end

The value of score is assigned within globalfun and will be set as return value. Then call it from a script or another function

myscore = globalfun(a, xr, x)

If you need multiple return values, use square brackets

function [i,j,score] = globalfun(a, xr, x)
    ...
    i = ...
    j = ...
    score = gv_0/gv_1;
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.