Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!postnews.google.com!1g2000prg.googlegroups.com!not-for-mail
From: NZTideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to be a good Matlab programmer
Date: Sat, 19 Apr 2008 20:41:53 -0700 (PDT)
Organization: http://groups.google.com
Lines: 51
Message-ID: <24786fa9-8a09-4dbc-8621-2e7e09053bbf@1g2000prg.googlegroups.com>
References: <d6f9728b-07d7-4ebc-8264-e2485cde6259@c65g2000hsa.googlegroups.com> 
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1208662914 1991 127.0.0.1 (20 Apr 2008 03:41:54 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 20 Apr 2008 03:41:54 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: 1g2000prg.googlegroups.com; posting-host=202.78.152.105; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; 
Xref: news.mathworks.com comp.soft-sys.matlab:464094


On Apr 20, 1:38=A0pm, Dave Bell <db...@TheSPAMFREEBells.net> wrote:
> Rex wrote:
> > On Apr 19, 7:23 pm, dpb <n...@non.net> wrote:
> >> I assume you've read the section in the online documentation on
> >> "Optimizing Matlab Code" in the m-file programming section?
>
> >> --
>
> > Yes, I have; that is the type of resource I am looking for. However, I
> > want to be clear that I'm not just looking for tips on optimizing the
> > performance of my code; =A0I also want to learn to write more elegant
> > and concise code.
> > Rex
>
> That was a good example of what I encountered as a new Matlab user, as
> well. It's an entirely different programming paradigm, and it takes a
> while to get used to. (I still program Matlab like C!)
>
> Another issue I ran into was simply searching for help. When I was
> trying to speed up a project I was working on, someone suggested using
> benchmark before and after changing some code. Not wanting to seem
> dumber than I was, I didn't ask how to benchmark my code, I just figure
> I'd look it up. Try it - there is no such command. One of the two hits I
> got from 'Help benchmark' was an article on training a neural net, the
> other was about a Simulink model of a Physics 1 experiment with a cart
> and mass. I won't admit to how long it took to find 'bench'!
>
> Dave

There are some lessons we learn from bitter experience.  Like (using
your example):
dims =3D [10 18 21 25 40 65];
for i =3D dims,
    dlmwrite(sprintf('matrix%d', i), ones(i));
end
-
-
y=3Damp.*exp(i*phase);

But now, i=3D65, not sqrt(-1).
Lesson: NEVER use i or j as an index

Even if this were in a textbook somewhere (and it probably is), I
think you must make the mistake in order to learn your folly.

But, IMHO, the best way to learn style is to read CSSM, especially
from posters such as "us".  If you read his posts and follow his code
(even if it is irrelevant to you), you will learn lots about style
(and new tricks as well).