0

I need to repeat this code many times. It is part of system-tester.

testFvB=@(fBE,fMCS,CI) 
{
    d='FV';
    dF=strcat('testing/systemTestFiles/D_', fBE, '_', fMCS, '_', d, '.txt');
    bepo(fBE,CI,fMCS,d,dF,oF);

    d='B';
    oF=strcat('testing/systemTestFiles/O_', fBE, '_', fMCS, '_', d, '.txt');
    bepo(fBE,CI,fMCS,d,dF,oF);
};

but

Error: File: systemTester.m Line: 3 Column: 6
The expression to the left of the equals sign is not a valid target for an
assignment.

I don't know but it looks like Matlab does not accept anonymous functions of this large size. So how to use anonymous functions to encapsulate larger codes not just things like doIt=@(x) x+1? Is the only way for the encapsulation here to create a new file?

[Update] not working, possible to make this into an execution?

test=@(fBE,fMCS)for d=1:2
    for CI=0:0.25:1
        if d==1
            d='FV';
        else
            d='B';
        end
        oF=strcat('testing/systemTestFiles/O_', fBE, '_', fMCS, '_', d, '.txt');
        bepo(fBE,CI,fMCS,d,dF,oF);
    end
end;

fBE='TestCase1 BE Evendist v2.txt';
fMCS='TestCase1 MCS.txt';
test(fBE,fMCS)

1 Answer 1

3

Anonymous functions can only contain a single executable statement.

So in your case, just create a regular M-file function.


If you are interested, there is a series of articles on Loren Shure's blog introducing functional programming style, using anonymous functions to do non-simple tasks.

Sign up to request clarification or add additional context in comments.

2 Comments

The code has a repeating pattern, updated. Is it possible to make it into an execution?
doesnt matter, you cant put multiple statements in an anonymous function. Besides why not just create a regular function?

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.