Need help with for and while loops.
1 view (last 30 days)
Show older comments
Christian Maynard
on 23 Mar 2015
Commented: Christian Maynard
on 23 Mar 2015
I have two assignments in my programming class that I'm struggling in. Either of them deal with for loops or while loops. The first one that deals with for loops, requires that we write a code that can multiply matrices. Although there are commands that already do this, we must understand how the for loop works and do it for ourselves.
The second one deals with while loops. It is the same concept as the first, but we must write code that completes the bubble sort algorithm. I won't worry about this one for now.
Any direction on help, advice, or answers here, is greatly appreciated.
0 Comments
Accepted Answer
James Tursa
on 23 Mar 2015
Matrix Multiply: Start with the MATLAB doc for this, in particular the formula for the element C(i,j) of the result from this page:
Code up that formula pretty much exactly as it is written, and then wrap it inside a couple of for loops for the i and j.
Bubble Sort: You can look at this page for pseudo code for this algorithm, and then translate it into MATLAB code:
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!