フィルターのクリア

syntax error in if else if block

3 ビュー (過去 30 日間)
Maya
Maya 2024 年 5 月 20 日
コメント済み: Torsten 2024 年 5 月 20 日
how to write else if condition with multiple inputs
else if condition is throwing an error.
  1 件のコメント
Infinite_king
Infinite_king 2024 年 5 月 20 日
編集済み: Infinite_king 2024 年 5 月 20 日
Can you share the exact error message ?

サインインしてコメントする。

回答 (2 件)

Hassaan
Hassaan 2024 年 5 月 20 日
編集済み: Hassaan 2024 年 5 月 20 日
% Number of inputs: 3
% If expression (e.g., u1 ~= 0):
u1 == 1
% Elseif expressions (comma-separated list, e.g., u2 == 2, u3 == 3):
(u2 == 2) && (u3 == 3)
% Show else condition:
Ensure that each condition within the Elseif expressions field is properly formatted using logical operators like && (AND) or || (OR).
Separate multiple elseif expressions with commas, if there are more than one.
Here’s the corrected entry based on your input:
If expression:
u1 == 1
Elseif expressions:
(u2 == 2) && (u3 == 3)
Ensure there are no extra spaces or unbalanced parentheses.
Double-check variable names and ensure they match the input names used in your Simulink model.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  1 件のコメント
Maya
Maya 2024 年 5 月 20 日
tried the same but still same error.

サインインしてコメントする。


Aman
Aman 2024 年 5 月 20 日
Hi Maya,
You are getting this error because the square brackets and '&&' are not allowd in IF block. The allowed opertators are <, <=, ==, ~=, >, >=, &, |, ~, ( ), unary-minus. So the modified equation as per this would be as below.
(u2==2) & (u3==3)
I hope this helps!
  2 件のコメント
Maya
Maya 2024 年 5 月 20 日
Hello Aman,
I want the logical AND to perform. "&" will give other result.
Torsten
Torsten 2024 年 5 月 20 日
I think you must delete all spaces in the second condition:
u2==0&u3==2

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by