Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!news.litech.org!News.Dal.Ca!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: matlab random object
Date: Fri, 11 Jul 2008 18:59:57 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 72
Message-ID: <g58ajd$a3f$1@canopus.cc.umanitoba.ca>
References: <g57qt2$s1s$1@fred.mathworks.com> <g583sm$bsc$1@fred.mathworks.com> <g584c3$17v$1@canopus.cc.umanitoba.ca> <g5892p$9q7$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1215802797 10351 192.70.172.160 (11 Jul 2008 18:59:57 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Fri, 11 Jul 2008 18:59:57 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:478900



In article <g5892p$9q7$1@fred.mathworks.com>,
ching l <chinglnc@hotmail.com> wrote:

>can i have a couple of basic question please?

>I've always seen these dots ... , what are these dots mean?

In the matlab help, click on "Functions -- By Category",
and once there, "Programming and Data Types", then
"Operators and Special Characters" from there, and then
the "Special characters" section of that. The ... will be
listed there with a link; if you click on that you will get
a more extensive writeup.

Alternately, you could just enter the search string
special characters
in the matlab help search box; the longer writeup is in
the first result there.

... Continuation. Three or more periods at the end of a line continue
    the current function on the next line. Three or more periods before
    the end of a line cause MATLAB to ignore the remaining text on the
    current line and continue the function on the next line. This
    effectively makes a comment out of anything on the current line
    that follows the three periods. See Entering Long Statements (Line
    Continuation) for more information.


>and what is {:} means?

In the code I showed, I used the trick documented in the "Cell Arrays"
documentation:


  Replacing Lists of Variables with Cell Arrays

  Cell arrays can replace comma-separated lists of MATLAB variables in
  o Function input lists
  o Function output lists
  o Display operations
  o Array constructions (square brackets and curly braces)

  If you use the colon to index multiple cells in conjunction with
  the curly brace notation, MATLAB treats the contents of each cell
  as a separate variable. For example, assume you have a cell array
  T where each cell contains a separate vector. The expression
  T{1:5} is equivalent to a comma-separated list of the vectors in
  the first five cells of T.


The syntax {:} is the same as {1:end} -- that is, indexing all
of the cell array contents, and creating a comma-seperated list
out of the result. In my code, I constructed each cell member
to have two elements, the first being the list of samples, and the
second being the sample frequency Fs returned by wavplay.
Using {:} on the cell array in the call to wavplay was equivilent
to having given wavplay two separate parameters, one for the data
samples and the other for the sampling frequency.
We don't know that the sampling frequency was the same for each
of the .wav files, so if we were to play them back all with the same
sampling frequency, some of them might have been at the wrong speed,
so we have to remember the sampling frequency for each file and
tell wavplay to use that frequency.

I could have used two different arrays to store the samples and the
frequencies, but then I would have had to temporarily store the
random number in order to use it to index both arrays at the same
offset; I would have had to have used a second anonymous function
to handle that situation, or else would have to have used a non-
anonymous function (anonymous functions cannot construct local variables.)
-- 
'Roberson' is my family name; my given name is 'Walter'.