Simple Matlab Query

Discussion in 'Programmer's Corner' started by JackSmall, Apr 16, 2007.

  1. JackSmall

    Thread Starter New Member

    Apr 16, 2007
    I am a real beginner with Matlab and am struggling to work my way through a script provided by a lecturer.

    I have the lines:

    Code ( (Unknown Language)):
    1. Data=load ('DataFile');
    2. Data1_Temp =Data.Test1FinalArray(:,:,3:20)
    and I'm not entirely sure I understand what the second line is doing. I've never seen an array be referenced with 3(!) parameters. Any help would be much appreciated.

  2. ninotna77

    New Member

    Apr 16, 2007
    Hey - I'm sorry for my english, I'm not from english speaking country


    means that Data.Test1FinalArray is a 3D array
    (it is often used in image processing, where 2 dimensions are used
    for image itself, and the 3rd dimension is for chanel Red, Green, Blue)

    Data.Test1FinalArray:),:,3:20) takes all the ellements (samples) from
    the first and second dimension, but only from 3 to 20 in the 3rd dimension.

    simplier example:
    a = [1 2 3 4; 5 6 7 8; 9 10 11 12];

    2 3 4
    a:),2:4) is then 6 7 8
    10 11 12

    You can also find a good help in matlab, just type "demo" and press enter
    and then in the chapitre Matlab-Programming-Manipulating Multidimension Arrays

    Data.Test1FinalArray means just that Data is a structure with an object Test1FinalArray.

    Don't hesitate to ask me - if you have any trouble with Matlab

  3. Dave

    Retired Moderator

    Nov 17, 2003
    Further to the information given by ninotna77:

    You find the colon operator :) ) one of Matlab's most powerful tools, particularly when vectorising code to optimise it. Since Matlab is an interpretted language, it can be quite slow when wading through lengthy code fragments such as for-loops, therefore by vectorising with the colon operator you can speed up your code 10-fold.

    Open the Matlab help, and type "colon" in the search box to find its many uses.