0

To reduce the size of a program with repetitive parts, I want to make a loop. But I got the following problem:

 for n=1:4
    .
    .
    .

    [A,B,C,D] =  ['A002A_' num2str(n)] '_Filtre'(matrices{:});  
    .
    .
  end

??? Error: Unexpected MATLAB expression.

this line is to replace:

[A, B, C, D] = A002A_1_Filtre(matrices {:});

the loop is made on the position of the value 1

1 Answer 1

1

You need to use eval when you want to dynamically evaluate commands in MATLAB based on creating strings. What you're doing in the loop is that you are trying to construct a string and magically assigning the string to four variables A,B,C,D. If you want a command to execute, use eval. In other words, do this:

for n=1:4
   .
   .
   .
   [A,B,C,D] =  eval(['A002A_' num2str(n) '_Filtre(matrices{:});']);  
   .
   .
 end

Make sure that eval contains a string. This string is essentially the command you want MATLAB to execute.

NB: This is assuming that matrices is already defined in your workspace prior to using this code. As such, make sure matrices is declared.

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.