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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started