Question: code in MATLAB Write a function that, given a single vector as the input calling argument, calculates and returns the sum of the elements beginning
code in MATLAB
Write a function that, given a single vector as the input calling argument, calculates and returns the sum of the elements beginning with the first element ending at the first zero (or the end of the vector).
You must use looping with the appropriate indexing to accomplish this task. The result is returned by the function, not printed by the function.
For example, given input vector [ 1 1 1 0 2 2 0 3 3 ], the result would be 3
For example, given input vector [ 1 -2 7 ], the result would be 6
For example, given input vector [ 5 6 7 0 1 2 3 4 ], the result would be 18
For example, given input vector [ 0 -1 2 ], the result would be 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
