How would you add every third number, starting with 1, under 100 and create an array?
Show older comments
I am not the familiar with matlab syntax
Answers (2)
Image Analyst
on 7 Jul 2018
Try this:
% Create a 1-D vector:
% Every third number starting with 1 up to but not exceeding 100.
v = 1 : 3 : 100
% Do the addition
theSum = sum(v)
2 Comments
Hannah Bartolo
on 8 Jul 2018
Image Analyst
on 8 Jul 2018
Hannah, when you get around to actually trying it you'll see this in the command window:
>> v = 1 : 3 : 100
v =
Columns 1 through 19
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55
Columns 20 through 34
58 61 64 67 70 73 76 79 82 85 88 91 94 97 100
Since you didn't want the 100 but wanted to end at 97 and wanted your vector named a instead of v, you'd do
>> a = 1 : 3 : 97
Akshay Srivastava
on 9 Jul 2018
0 votes
mat = 1:3:100, if you want the vector to be [1,4,7...100] and try mat = 1:3:97 if you want the vector to be [1,4,7,...,97].
Categories
Find more on Whos 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!