English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Relational operators can also handle scalar and non-scalar data. Array relational operators perform element-by-element comparison between two arrays and return a logically sized array of the same size, with elements set to logical1(true), the relationship is true, the element is set to logical 0(false). Not.
The following table shows the relational operators-
Serial Number | Operators and Descriptions |
---|---|
1 | < Less |
2 | <= Less than or equal |
3 | > Greater |
4 | >= Greater than or equal |
5 | == Equal |
6 | ~= Not equal |
Create a script file and enter the following code-
a = 100; b = 200; if (a >= b) max = a else max = b endWhen you run the file, it will produce the following result-
max = 200
In addition to the above relational operators, MATLAB also provides the following commands for the same purpose/Function-
Serial Number | Function Description |
---|---|
1 | eq(a, b) Test if a is equal to b |
2 | ge(a, b) Test if a is greater than or equal to b |
3 | gt(a, b) Test if a is greater than b |
4 | le(a, b) Test if a is less than or equal to b |
5 | lt(a, b) Test if a is less than b |
6 | ne(a, b) Test if a is not equal to b |
7 | isequal Test if the array is equal |
8 | isequaln Test if the array is equal, treating NaN values as equal |
Create a script file and enter the following code-
%Comparison of two values a = 100; b = 200; if (ge(a, b)) max = a else max = b end %Comparison of two different values a = 340; b = 520; if (le(a, b)) disp('a is less than or equal to b') else disp('a is greater than b') endWhen running the file, it will produce the following result-
max = 200 a is less than or equal to b