write an m-file using while loop which calculates the sum of elements within the following vector x=[5 2 -9 10 -1 9 -1] until a number greater than 8 is met? please help i have tried and i am confused on how to do this.
Ältere Kommentare anzeigen
i have tried and my codes don't work, how can i do this with a while loop?
2 Kommentare
the cyclist
am 6 Okt. 2015
I assume this is a homework assignment. I suggest you post what you have tried and we can suggest where you went wrong.
kelechi okegbe
am 6 Okt. 2015
Bearbeitet: kelechi okegbe
am 6 Okt. 2015
Akzeptierte Antwort
Weitere Antworten (1)
Joseph Cheng
am 6 Okt. 2015
general outline would be
x=[5 2 -9 10 -1 9 -1];
while currentsum<=8
currentsum = %what you want to sum up.
end
2 Kommentare
kelechi okegbe
am 6 Okt. 2015
Walter Roberson
am 6 Okt. 2015
"%what you want to sum up." should only be a subset of x, not all of x. Your loop should be incrementing the index of the last element that you are paying attention to. sum(x(1:SomeIndex)) and keep increasing SomeIndex. Make sure you stop when you reach the end of the array.
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!