Thursday, October 25, 2007

Matlab VI

Basics of For Loops

Everything I have showed you on Matlab Tutorial up to this point has been pretty simple and straight forward. But now I'm going to show a simple command that is the root to all of Matlab programming. It can be a simple command, but as you get better and better at using the system, you find that this command can be very large and complicating as well. This command is the "for loop". The command is used to perform equations or other actions as many times as specified by the index of the code. The syntax really isn't that bad, it's the the fact that you can have a lot of extra stuff inside the command to make things complex.

The first line of code starts with for X = Index bounds. The bounds can either be used with the colon command or linspace.

A quick lesson on both the colon command and linspace command, because I had failed to explain this before loops. Both of these commands are a way to count and display a series of number to you see fit. The colon command is simply [Start : Increment : End], where the first term is your starting value, the middle term is how much you go up or down (Negative increments count backwards), and your last value is the value the sequence stops at. Linspace is a little different, but is written in code as linspace (Start, End, #), where the first term is the start value, the second is the last value, and the last term is how many terms you want to consist in the sequence.

Now that you know how to count sequences, the for loop should be easier. So the first line can now be completed as for X = 1 : 1 : 10 for example, having the loop go from 1 to 10 in increments of 1. Now what you do with this index and your for loop has really endless possibilities. You could make another for loop inside your first, some logical statement, a summation, or another type of loop. For a simple example, you could have the for loop find values for an equation such as X^2 + 5 for each value of the index and display those in terms of a variable F. This would be written in as the next line, indented from the first: F = X^2 + 5 , where F would be displayed as the value of the equation with X changing each time. To end your loops, always have end indented as far as the for syntax. This example for loop would then run and output each of ten values in the equation F.

So that is the basics to making a safe for loop. Stay tuned to learn how to make other loops! Have a good week and weekend everyone!

Sorry for the title misspelling, it is called a for loop not a four loop.

Resources: Matlab Code


Anonymous said...

Compare hit village Our Unclear Prices at, The Fantastic [b][url=]Online Dispensary [/url][/b] To [url=]Buy Viagra[/url] Online ! You Can also Presage Primed Deals When You [url=]Buy Cialis[/url] and When You You [url=]Buy Levitra[/url] Online. We Also Performers a Operative Generic [url=]Phentermine[/url] In compensation Your Meals ! We Vend Permanent epithet [url=]Viagra[/url] and Also [url=]Generic Viagra[/url] !

Anonymous said...

Predilection casinos? digging this still in diapers [url=]casino[/url] advisor and wing it crop online casino games like slots, blackjack, roulette, baccarat and more at .
you can also from our up to date [url=]casino[/url] orientate at and tone down corporeal bucks !
another late-model [url=]casino spiele[/url] purlieus is , because german gamblers, sprig in magnanimous online casino bonus.

Anonymous said...

Making money on the internet is easy in the underground world of [URL=]blackhat seo world[/URL], You are far from alone if you haven’t heard of it before. Blackhat marketing uses little-known or little-understood avenues to build an income online.

Anonymous said...

What's Up people, fantastic message board I find It exceedingly helpful & it has helped me out tons
I hope to be able to give something back and aid other users like this message board has helped me

[url=]iphone forum[/url]

Anonymous said...

unlock iphone 4
how to unlock iphone 4

unlock iphone 4 how to unlock iphone 4 unlock iphone 4
unlock iphone 4

unlock iphone 4 unlock iphone 4 [url=]unlock iphone 4 [/url] unlock iphone 4