Problem adding components of a vector using a while loop
Show older comments
Can anyone tell me what's wrong with this code?
x = [1 23 43 72 87 56 98 33];
b = 0;
k = 1;
while k<=length(x)
b = b+k(x)
k = k+1
end
I get index exceeds matrix dimensions. Thank you very much for your help
1 Comment
Mary Jeppson
on 12 May 2016
Accepted Answer
More Answers (1)
Stalin Samuel
on 11 May 2016
0 votes
replace b = b+k(x) into b = b+x(k)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!