File Exchange Pick of the Week

October 26th, 2007

MATLAB Basics: Linearly spaced vectors

When I look at code written by new users, sometimes, I will see code like this:

a = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];

There is an easier way:

a = 1:13;

This three minute video shows how to use commands like linspace and the colon operator to make vectors like:
[1 2 3 4 5] or [-1 -0.5 0 0.5 1].

Video Content

Find the files here.

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

Other MATLAB Basics posts have been gathered here:
http://blogs.mathworks.com/pick/category/matlab-basics/

One Response to “MATLAB Basics: Linearly spaced vectors”

  1. Muddasser Alam replied on :

    Excellent, thanks a lot!

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Beats: Not useful for everyday but very interesting. Thanks.
  • nickey: Hi Brett, I’ve tested Tao’s program and yours too. They ran successfully. I’ve tried to...
  • Kika: THANK YOU!! I’ve been trying to change the colormap but I didn’t know what to do. It was driving me crazy!...
  • Richard: Hello Doug, yet another question. I followed this tutorial: http://blinkdagger.c om/matlab/matlab-...
  • Doug: Richard, Use the compiler options file, it is found at the bottom of the dialog that you get when clicking on...
  • Richard: To whom it may concern, a solution to the dos screen annoyance is found by user ‘vihang’ in this...
  • Richard: Thank you for your reply. I understand that I can specify flags using the mcc command, but is this also...
  • Doug: Richard: Find it here: http://www.mathworks .com/access/helpdesk /help/toolbox/compil er/mcc.html Doug
  • Richard: Hello Doug, Can you explain point 56. (about the -e flag) because I can’t seem to find it. Regards,...
  • Doug: Tony, When you say the .MAT file has 984 files, you mean it has the *names* of the files. So the real problem...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.