EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials Matlab Tutorial Matlab quantile

Matlab quantile

Updated March 6, 2023

Matlab quantile

Introduction t0 Matlab quantile

Quantile function is used in MATLAB to divide a sample into adjacent, equal-sized subgroups. Quantile is also referred to as ‘fractile’, and in statistics, it is used to divide a given probability distribution into small areas which have equal probability.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

The median in statistics, for example, is a quantile which is placed inside a probability distribution such that half of the data is less than it and the other half is more than it. So, it divides a probability distribution into 2 equal areas and is called a 2-quantile.

Syntax of the quantile function:

A = quantile (nr, prob)

A = quantile (nr, X)

Details of the quantile function:

  1. A = quantile (nr, prob) is used to return quantiles for the elements present in a vector or array for the probability ‘prob’, which lies in the range [0,1].
  2. A = quantile (nr, X) is used to return the quantiles for ‘X’ equally placed cumulative probabilities. Mathematically, this is given by (1 / (X + 1), 2 / (X + 1), …, X / (X + 1)) for integer X > 1

Examples of Matlab quantile

Let us now understand how to use the quantile function in MATLAB.

Example #1

This example will use the quantile function to find a quantile for 12 normally distributed numbers. We will use the ‘normrnd’ function of MATLAB to get these normally distributed numbers. Below are the steps to be followed:

  1. Use normrnd function to get 12 random normally distributed numbers
  2. Pass these numbers to the quantile function to get the quantile. For this example, we will calculate the 0.4 quantile

Code:

nr = normrnd (0, 1, 1, 12)

[Initializing 12 normally distributed random numbers]

A = quantile (nr, 0.40)

[Passing the numbers generated above as input to the quantile function to get the 0.4 quantile]

This is how our input and output will look like in MATLAB:

Input:

Matlab quantile output 1

Output:

Matlab quantile output 2

As we can see, we have obtained 0.4 quantile for our 12 normally distributed random numbers. This means that 40% of our numbers are below -0.0987, and the rest 60% are above it.

Example #2

In this example, we will use the quantile function to find quantiles for a matrix. We will use a 3 x 3 matrix of probabilities and will calculate quantiles, first for its columns and then for its rows. We will use the ‘normrnd’ function of MATLAB to get these normally distributed numbers as the elements of the matrix. Below are the steps to be followed:

  1. Use the normrnd function to get random normally distributed elements for the matrix.
  2. Pass these numbers to the quantile function to get the quantiles for columns. For this, we will have to pass the ‘dim’ argument as 1, which represents ‘columns.’
  3. Pass these numbers to the quantile function to get the quantiles for rows. For this, we will have to pass the ‘dim’ argument as 2, which represents ‘rows.’

Code to calculate quantile for columns:

nr = normrnd (0, 1, 3, 3)

[Initializing a 3 x 3 matrix with normally distributed elements]

A = quantile (nr, 0.40, 1)

[Passing the matrix created above as input to the quantile function to get the 0.4 quantile. Please note that we have passed ‘1’ as the 3rd argument, which represents that the calculation is to be performed along the column]

This is how our input and output will look like in MATLAB:

Input:

Matlab quantile output 3

Output:

Matlab quantile output 4

As we can see, we have obtained 0.4 quantile for the columns of our 3 x 3 matrix of normally distributed random numbers.

Code to calculate quantile for rows:

A = quantile (nr, 0.40, 2)

[Passing the matrix created above as input to the quantile function to get the 0.4 quantile. Please note that we have passed ‘2’ as the 3rd argument, which represents that the calculation is to be performed along the row]

This is how our input and output will look like in MATLAB:

Input:

output 5

Output:

output 6

As we can see, we have obtained 0.4 quantile for the rows of our 3 x 3 matrix of normally distributed random numbers.

Example #3

In this example, we will use the quantile function to calculate evenly distant quantiles. We will use the ‘normrnd’ function of MATLAB to get 8 normally distributed numbers.

Code:

nr = normrnd (0, 1, 1, 8)

[Initializing 8 normally distributed random numbers]

A = quantile (nr, 3)

[Passing the numbers generated above as input to the quantile function to get 3 evenly distant quantiles]

This is how our input and output will look like in MATLAB:

Input:

output 7

Output:

output 8

As we can see, we have obtained 3 evenly distant quantiles for our 8 normally distributed random numbers.

Conclusion

  1. Quantile function is used in MATLAB to divide a distribution into smaller parts.
  2. An ‘x%’ quantile means that ‘x%’ of numbers are below this quantile, and the rest are above it.
  3. Quantile function can be used to find quantiles for both arrays and matrices.

Recommended Articles

This is a guide to Matlab quantile. Here we discuss how to use the quantile function in MATLAB along with the examples and outputs. You may also have a look at the following articles to learn more –

  1. Matlab limit
  2. Matlab Cell
  3. Matlab Scripts
  4. What is Matlab?
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
62+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests
 11+ Hours of HD Videos
5 Courses
3 Mock Tests & Quizzes
  Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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

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

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more