Doug’s MATLAB Video Tutorials

August 27th, 2009

Basics: Implementing a formula in MATLAB

This video will demonstrate how to implement a formula in MATLAB. In the video, we will make a function out of the formula. The function will take a scalar (single number) or a vector. We want to make the function take either a scalar or a vector so that you do not have to loop through calling the function. This is not for speed, but for the simplicity and readability of the code. This vectorization is done by means of array division ( ./ ) and array multiplication ( .* ). These operations do division and multiplication on an element by element basis.

4 Responses to “Basics: Implementing a formula in MATLAB”

  1. Matt Fig replied on :

    Hey Doug,

    What’s twits.txt, some kind of ML hit-list?

    :-)

  2. dhull replied on :

    Matt!

    Nice catch. That is actually a list of twitter comments that I post once a day to Twitter.com. It is a very short MATLAB example (less than 140 characters including the tag #MATLAB)

    Take a look at the feed here:
    http://twitter.com/matlabDoug

    Thanks for keeping me on my toes!

    -doug

  3. Ismael replied on :

    I whould like to know how to show in a GUI window a formula, i mean a formula like the one you have in the first snapshot of this video tutorial, not the graphical representation.
    And i would like to know which kind of element in the GUI i need to use. Thanks in Advance

  4. dhull replied on :

    @Ismael,

    You can use the TeX and LaTeX parts of MATLAB for some formulas. For the one above, that was just a screenshot of an e-mail the user sent me.

    Doug

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


Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

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