Question: Code in matlab Write a function that, given a single vector as the input calling argument, calculates and returns the product of the elements that

Code in matlab

Write a function that, given a single vector as the input calling argument, calculates and returns the product of the elements that are nonzero.

You must use branching and 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 2 3 ], the result would be 6

For example, given input vector [ 3 2 0 2 ], the result would be 12

For example, given input vector [ 2 11 3 -1 ], the result would be -66

For example, given input vector [ 0 -1 0 -1 -1 0 ], the result would be -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!