Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:58:49+00:00 2026-05-17T19:58:49+00:00

I came across some MATLAB syntax with a colon that I don’t fully understand.

  • 0

I came across some MATLAB syntax with a colon that I don’t fully understand.

First Question:

The expression: 0:pi/4:pi
results in the answer: 0 0.7854 1.5708 2.3562 3.1416

Why is this the case? I thought that colon operator is used as a quick way to refer to indices so that we don’t have to write out the full list. (e.g. 1:3 -> 1 2 3)

Second Question:

Similar to above, say if I have a matrix X = [1 2 3 4 5 6 7 8 9]. How can I interpret the expression X(:,1:3)? Specifically, what does the colon operator without the left and right numbers mean?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:58:50+00:00Added an answer on May 17, 2026 at 7:58 pm

    Actually a:b generates a vector. You could use it as index only because the (...) accepts a list also, e.g.

    octave-3.0.3:10> a = [1,4,7]
    a =
    
       1   4   7
    
    octave-3.0.3:11> b = [1,4,9,16,25,36,49]
    b =
    
        1    4    9   16   25   36   49
    
    octave-3.0.3:12> b(a)    # gets [b(1), b(4), b(7)]
    ans =
    
        1   16   49
    

    Now, the a:b:c syntax is equivalent to [a, a+b, a+2*b, ...] until c, e.g.

    octave-3.0.3:15> 4:7:50
    ans =
    
       4  11  18  25  32  39  46
    

    which explains what you get in 0:pi/4:pi.


    A lone : selects the whole axes (row/column), e.g.

    octave-3.0.3:16> a = [1,2,3;4,5,6;7,8,9]
    a =
    
       1   2   3
       4   5   6
       7   8   9
    
    octave-3.0.3:17> a(:,1)   # means a(1:3, 1)
    ans =
    
       1
       4
       7
    
    octave-3.0.3:18> a(1,:)   # means a(1, 1:3)
    ans =
    
       1   2   3
    

    See the official MATLAB doc on colon (:) for detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking over some code and I came across some syntax that I don't
I came across some regular expressions that contain [^\\p{L}] . I understand that this
I came across some interesting C# syntax that I'm not familiar with in the
I came across some Java syntax that I haven't seen before. I was wondering
I came across some javascript code I don't understand: what does a < 5
I came across some matlab code that did the following: thing.x=linspace(... I know that
I came across some results in a program I was writing that confused me.
I came across some javascript at work today that used jQuery to fetch two
I came across some legacy code that contains a function like this: LPCTSTR returnString()
I came across some code today that surprised me. A variable was defined (outside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.