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

Watch our Demo Courses and Videos

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

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?

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