Thread Subject: A simple question about FOR

Subject: A simple question about FOR

From: Kamil

Date: 26 Feb, 2008 18:20:41

Message: 1 of 4

Dear Colleagues,

I am wondering, if there was a simple way to suppress 'for' command in
MATLAB.
This would force students to use smarter solutions than just a lot of
for loops and waiting :)
If You have some hint how to do it in ver.2007b, let me know.
Best Regards
Kamil

Subject: A simple question about FOR

From: David

Date: 26 Feb, 2008 18:33:02

Message: 2 of 4

Kamil <milka-wywal@to.free.of.pl> wrote in message
<fq1lcs$t07$1@atlantis.news.tpi.pl>...
> Dear Colleagues,
>
> I am wondering, if there was a simple way to
suppress 'for' command in
> MATLAB.
> This would force students to use smarter solutions than
just a lot of
> for loops and waiting :)
> If You have some hint how to do it in ver.2007b, let me
know.
> Best Regards
> Kamil

class policy??? -10 points for every 'for' in an
assignment.

Subject: A simple question about FOR

From: Loren Shure

Date: 26 Feb, 2008 18:47:19

Message: 3 of 4

In article <fq1m0u$qlo$1@fred.mathworks.com>, dave@bigcompany.com
says...
> Kamil <milka-wywal@to.free.of.pl> wrote in message
> <fq1lcs$t07$1@atlantis.news.tpi.pl>...
> > Dear Colleagues,
> >
> > I am wondering, if there was a simple way to
> suppress 'for' command in
> > MATLAB.
> > This would force students to use smarter solutions than
> just a lot of
> > for loops and waiting :)
> > If You have some hint how to do it in ver.2007b, let me
> know.
> > Best Regards
> > Kamil
>
> class policy??? -10 points for every 'for' in an
> assignment.
>

My thesis advisor used to deduct 5 points :-)

--
Loren
http://blogs.mathworks.com/loren/

Subject: A simple question about FOR

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 26 Feb, 2008 19:56:15

Message: 4 of 4

In article <fq1lcs$t07$1@atlantis.news.tpi.pl>,
Kamil <milka-wywal@to.free.of.pl> wrote:

>I am wondering, if there was a simple way to suppress 'for' command in
>MATLAB.
>This would force students to use smarter solutions than just a lot of
>for loops and waiting :)

Sometimes using a 'for' or 'while' loop *is* the most efficient way.

For example a couple of weeks ago, I had a case in which the
standard matlab method of writing a section of code was roughly

[X,Y] = ndgrid(A,B);
answer = sum(X < Y);

Now allow A and B to grow to roughly 1200 elements each, and
call this code 100,000 times, and these two lines of code took
approximately 26.13 minutes to execute.

After some thought, I replaced this short code with a 'while'
loop that took noticably more coding lines, but was linear in the
size of A (and independant of the size of B). With the same dataset,
calling the same 100,000 times, the replacement code took 2.39 seconds
total to execute.

Now, if I were to turn in that 'while' solution that was ~50 times
faster than anyone else achieved using matlab vectorized operations,
would you fail me on the assignment for not using a sufficiently
"smart" solution?
--
  "The beauties of conception are always superior to those of
   expression." -- Walter J. Phillips

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com