Can someone give an example of a for loop for this problem?: Find the sum of 30 numbers that increments by 3. The starting number is 4. Thanks!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
TSmith
am 7 Dez. 2018
Kommentiert: madhan ravi
am 11 Dez. 2018
Just a simple for loop please. Nothing too complicated. Thank you again.
2 Kommentare
Steven Lord
am 7 Dez. 2018
In general if you post a question like this that sounds like a homework assignment, even if it isn't a homework assignment, I recommend posting what you've tried and asking for help improving and/or fixing it. The problem might be as simple as a typo in your code, and seeing that code may allow someone to respond within seconds with the easy fix.
From your question itself, I'm guessing you're fairly new to MATLAB. If that's right, consider going through the free MATLAB Onramp course in the Tutorial section on the Support page if you haven't already. [Click Support in the bar at the top of this page.] It will teach you some of the basics of MATLAB and perhaps fill in any gaps in what you've learned so far.
Akzeptierte Antwort
Sean de Wolski
am 7 Dez. 2018
x = sum(4:3:(4+3*(30-1)))
8 Kommentare
John D'Errico
am 10 Dez. 2018
Bearbeitet: John D'Errico
am 10 Dez. 2018
@Madhan - don't worry about upvotes anyway. Reputation is not important, and there is no race to the top. Your responses are appreciated, improving the site with your presence, regardless of an upvote or not..
Weitere Antworten (1)
madhan ravi
am 7 Dez. 2018
Read about sum() and cumsum() loops are superfluous in this case
9 Kommentare
madhan ravi
am 7 Dez. 2018
Yes I just saw your comment in your previous question @TSmith , Best of luck!
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!