I have a code but it keeps sending this erreur message : Error: File: moo_object​ive_functi​ons.m Line: 4 Column: 89 Invalid expression. When calling a function or indexing a va

2 visualizaciones (últimos 30 días)
Here's the code :
  1. function f = moo_objective_functions (x)
  2. dispo = x(1) ; rule = x(2); iat= x(3) ; bs =x(4) ;
  3. f(1) = 144633 - [(13633* bs) - (5742.6 *iat) - (68028* rule) - (71627* dispo) + (542.4 *
  4. bs*iat) + (6511* bs*rule) + (6809 *bs*dispo) + (2721.8 *iat*rule) + (2845.2* iat*dispo)
  5. + (33807* rule*dispo) - (260.52* bs*iat*rule) - (269.48 *bs*iat*dispo) - (3235.7
  6. *bs*rule*dispo) - (1352.5 *iat*rule*dispo) + (129.46* bs*iat*rule*dispo)] ;
  7. f(2) = -[-61.61 + 9.883* bs + 4.1508* iat + 2.415* rule + 98.713* dispo -
  8. (0.50632* bs*iat)- (9.4912* bs*dispo) - (0.0971* iat*rule) - (3.9333 *iat*dispo) -
  9. (1.116* rule*dispo)+ (0.37771* bs*iat*dispo) + (0.0448* iat*rule*dispo)] ;
  10. end
and this is the 2 erreur messages :
Error: File: moo_objective_functions.m Line: 4 Column: 89
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
Error: File: moo_objective_functions.m Line: 4 Column: 89
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.

Respuestas (1)

Harshavardhan
Harshavardhan el 7 de Mzo. de 2025
The error messages you're encountering suggest that there is a problem with the syntax in your MATLAB code, specifically with the use of brackets and parentheses.  When splitting a statement across multiple lines in MATLAB, use the ellipsis ” ... “ to indicate that the statement continues on the next line. The code with the correct syntax is given below:
function f = moo_objective_functions (x)
dispo = x(1) ; rule = x(2); iat= x(3) ; bs =x(4) ;
f(1) = 144633 - ((13633* bs) - (5742.6 *iat) - (68028* rule) - (71627* dispo) + (542.4 * bs*iat) ...
+ (6511* bs*rule) + (6809 *bs*dispo) + (2721.8 *iat*rule) + (2845.2* iat*dispo) ...
+ (33807* rule*dispo) - (260.52* bs*iat*rule) - (269.48 *bs*iat*dispo) - (3235.7*bs*rule*dispo) ...
- (1352.5 *iat*rule*dispo) + (129.46* bs*iat*rule*dispo)) ;
f(2) = -(-61.61 + 9.883* bs + 4.1508* iat + 2.415* rule + 98.713* dispo ...
- (0.50632* bs*iat)- (9.4912* bs*dispo) - (0.0971* iat*rule) - (3.9333 *iat*dispo) ...
- (1.116* rule*dispo)+ (0.37771* bs*iat*dispo) + (0.0448* iat*rule*dispo)) ;
end
For more information on ellipsis in MATLAB, you can refer to the following link:

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by