Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Write a function catit that will receive one input argument which is a cell array. If the cell array contains only strings, it

Question 1

Write a functioncatitthat will receive one input argument which is a cell array. If the cell array contains only strings, it will return one string which is all of the strings from the cell array concatenated together-otherwise, it will return an empty string. Here is one example of calling the function:

>> fishes = {'tuna', 'shark', 'salmon', 'cod'};

>> catit(fishes)

ans=

tunasharksalmoncod

Question 2

Vectorize this code! Write one assignment statement that will accomplish exactly the same thing as the given code (assume that the variablevecis a vector and it has been initialized):

newv = zeros(size(vec));

myprod = 1;

for i = 1:length(vec)

myprod = myprod * vec(i);

newv(i) = myprod;

end

newv % Note: this is just to display the value

Question 3

Write a function function named:posnum that prompts the user to enter a positive number and loops to error-check until user enters positive number. It returns the positive number entered by the user and print it out on the screen. It calls a subfunction in the loop to print an error message. The subfunction has a persistent variable to count the number of times an error has occurred. [10]

Here is the sample output of calling the function: posnum

>> enteredvalue = posnum

Enter a positive number: -5

Error # 1 : Follow instructions!

Does -5.00 look like a positive number to you?

Enter a positive number: -33

Error # 2 . Follow instructions!

Does -33.00 look like a positive number to you?

Enter a positive number: 6

enteredvalue =

6

Question 4

Use MATLAB built-in functionrandto generate 10 random integers between 21 to 150 using and store those integers in a vectorv. If the integers are distributed evenly in this range, they should fall on a straight line when arranged from lowest to highest. Assume the sorted integers are stored in a vectorywith corresponding index vectorx, use the MATLAB to fit the integers into a straight line.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago