EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab not equal
 

Matlab not equal

Updated March 8, 2023

Matlab not equal

 

 

Introduction to Matlab not equal

The following article provides an outline for Matlab not equal. Matlab supports all types of operators such as arithmetic, logical, comparison, relational etc. In a relational operator group, there are various operations which decide the relation between two quantities. Relational operators are equal to (= =), not equal (~ =), greater than (>), less than (<) and so on. Every operator has two ways to implement in a program, one is by using syntax, and other one is by using operator symbol. Similarly, for Not equal operator is implemented in two ways: using the symbol ‘~=’ and using syntax ‘ne’. The output of both the methods will be the same.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

var1 ~= var2
first variable name ~= second variable name

ne(var1,var2)
ne(first variable name ,second variable name)

How not equal Operator Work in Matlab?

  • Not equal to operator compares two quantities or elements at a time and gives result in the form of true or false.
  • If both the elements are the same, then not equal to operation fails, and it gives the result as false similarly if both the elements are not same then not equal to condition satisfies then will be true.
  • True and False are represented in the form of once and zeros.
  • If the result is true, it will be represented as ‘1’, and if the result is false, it will be represented as ‘0’.

Examples of Matlab not equal

Given below are the examples of Matlab not equal:

Example #1

Let us consider one simple example of one element. The first element ‘11’ is declared as ‘var 1’, and the second elements ‘29’ is declared as ‘var 2’. In example 1(a), not equal operator used by the symbolic method and in example 1(c), the same problem illustrated by using syntax ‘ne’. In this two examples, elements are different; therefore, we will get the result as 1. In example 1(b) and 1(d), elements are the same; therefore, we will get the result as 0 by using both symbolic and syntax methods, respectively.

Matlab code for Example 1(a):

Code:

clear all;
disp ('Output');
var 1 = 11
var 2 = 29
var1 ~ = var2

Output:

Matlab not equal 1

Matlab code for Example 1(b):

Code:

clc;
clear all;
disp ('Output');
var 1 = 30
var 2 = 30
var1 ~ = var2

Output:

Matlab not equal 2

Matlab code for Example 1(c):

Code:

clc;
clear all;
disp ('Output');
var 1 = 50
var 2 = 29
ne (var1, var2)

Output:

Matlab not equal 3

Matlab code for Example 1(d):

Code:

clc;
clear all;
disp ('Output');
var 1 = 30
var 2 = 30
ne (var1, var2)

Output:

Matlab not equal 4

Example #2

In the previous example, input data was in a single element(single dimension), but if the data has multiple elements then not equal to operation will compare every element from the database and gives output individually for each element, which is illustrated in example 2(a) by using both the methods. In example 2(b), we can see data is multi-dimensional (matrix); it has three rows and four columns, so not the equal operation will work on every element of the matrix, and it will give result in the form of three rows and four columns.

Matlab code for Example 2(a):

Code:

clc;
clear all;
var 1 = [34, 54, 65] var 2 = [35, 54, 45] disp ('Output by ~ = operator -');
var 1 ~ = var 2
disp ('Output by ne syntax- ');
ne (var 1, var 2)

Output:

data has multiple elements

Matlab code for Example 2(b):

Code:

clc;
clear all;
var 1 = [5 6 3 2 ; 3 5 6 7 ; 2 7 8 4] var 2 =[4 5 3 1 ; 3 5 4 9 ; 6 5 3 4] disp('Output by ~ = operator -');
var 1 ~ = var 2
disp ('Output by ne syntax- ');
ne ( var 1, var 2)

Output:

Matlab not equal 6

Example #3

In this example type of input, arguments are different. Previously we have seen simple integers now; we will consider a complex variable as elements. Here the input is multidimensional as well as each element is a complex variable. On such type of dataset, not equal operator compares real and imaginary parts of every element and gives results accordingly, illustrated in example 3.

Code:

clc;
clear all;
var 1 = [5 + 6i, 3 + 3i, 2 - i] var2 = [ 6 + 7i, 3 + 3i, 6 - i] disp('Output by ~ = operator -');
var 1 ~ = var 2
disp ('Output by ne syntax- ');
ne ( var 1,var 2)

Output:

type of input arguments is different

Example #4

In this example, we will consider input in forms characters and strings. In example 4(a), first input is the word ‘hellomatlab’, and the second input is ‘m’, which is a single letter. The not equal operation will compare each element from a word with a single letter ‘m’, and it will give a result in the form of an array. And in example 4(b), the first input is an array of words which is compared with a single word, so not equal operator will compare all the words from the first input with the word ‘hello’, and it will also give output in the form of an array.

Matlab code for Example 4(a):

Code:

clc;
clear all;
var 1 = 'hellomatlab'
var 2 = 'm'
disp('Output by ~ = operator -');
var 1 ~ = var 2
disp('Output by ne syntax- ');
ne (var 1 ,var 2)

Output:

consider input in forms characters and strings

Matlab code for Example 4(b):

Code:

clc;
clear all;
var 1 = categorical({'hello', 'hi', 'hi', 'hello', 'hello', 'hi'})
var 2 = 'hello'
disp ('Output by ~= operator -');
var 1 ~ = var 2
disp ('Output by ne syntax- ');
ne (var 1,var 2)

Output:

Matlab not equal 9

Conclusion

In this article, we have seen various ways to use not equal operation in Matlab. The operator performs on each element of input irrespective of dimensionality of input data like single element, single dimension or multiple elements and multidimensionality. It performs on all data types such as integers, floating numbers, complex variables, characters and strings.

Recommended Articles

This is a guide to Matlab, not equal. Here we discuss the introduction, how not equal operator work in matlab and examples, respectively. You may also have a look at the following articles to learn more –

  1. Matlab gca
  2. Matlab xcorr
  3. Matlab plot title
  4. Matlab Sort

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW