Azzera filtri
Azzera filtri

Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parenthe

9 visualizzazioni (ultimi 30 giorni)
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;
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
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));

Risposta accettata

Les Beckham
Les Beckham il 24 Apr 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;
% ^ ^

Più risposte (1)

Walter Roberson
Walter Roberson il 24 Apr 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.

Community Treasure Hunt

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

Start Hunting!

Translated by