Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parenthe
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Les Beckham
2023-4-24
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 个评论
更多回答(1 个)
Walter Roberson
2023-4-24
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!