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

6 ビュー (過去 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;
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));

採用された回答

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

その他の回答 (1 件)

Walter Roberson
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.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by