Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parenthe
6 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Les Beckham
on 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;
% ^ ^
0 Comments
More Answers (1)
Walter Roberson
on 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.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!