Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parenthe
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yojp21
el 24 de Abr. de 2023
Respondida: Walter Roberson
el 24 de Abr. de 2023
I need some help to fix my code.
I keep getting error message, but I have not been able to find how I can fix the codes
error message
Invalid expression. Check for missing multiplication operator, missing or unbalanced
delimiters, or other syntax error. To construct matrices, use brackets instead of
parentheses.
my codes
IndexImg((Orientation >= pi/8 & Orientation < pi/4) | (Orientation >= -3pi/4 & Orientation < -5pi/8) & Magnitude >= EdgeThreshold) = 3;
EdgeImg((Orientation >= pi/8 & Orientation < pi/4) | (Orientation >= -3pi/4 & Orientation < -5pi/8) & Magnitude >= EdgeThreshold) = Magnitude((Orientation >= pi/8 & Orientation < pi/4) | (Orientation >= -3pi/4 & Orientation < -5pi/8));
% Label = 4 for 135 degree edges
IndexImg((Orientation >= -pi/4 & Orientation < -pi/8) | (Orientation >= 5pi/8 & Orientation <= pi/2) & Magnitude >= EdgeThreshold) = 4;
EdgeImg((Orientation >= -pi/4 & Orientation < -pi/8) | (Orientation >= 5pi/8 & Orientation <= pi/2) & Magnitude >= EdgeThreshold) = Magnitude((Orientation >= -pi/4 & Orientation < -pi/8) | (Orientation >= 5*pi/8 & Orientation <= pi/2));
0 comentarios
Respuesta aceptada
Les Beckham
el 24 de Abr. de 2023
You are missing the multiplication operator in several places. For example:
IndexImg((Orientation >= pi/8 & Orientation < pi/4) | (Orientation >= -3*pi/4 & Orientation < -5*pi/8) & Magnitude >= EdgeThreshold) = 3;
% ^ ^
0 comentarios
Más respuestas (1)
Walter Roberson
el 24 de Abr. de 2023
Orientation >= -3pi/4
MATLAB does not have any implied multiplication. 3pi is invalid in MATLAB.
Side note: I recommend using temporary variables
mask = (Orientation >= pi/8 & Orientation < pi/4) | (Orientation >= -3*pi/4 & Orientation < -5*pi/8) & Magnitude >= EdgeThreshold;
IndexImg(mask) = 3;
A|B&C is treated as A|(B&C) not as (A|B)&C .
I recommend that you use () to explicitly indicate the relative order you want for those operations, as readers might well have forgotten the rule.
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!