Question: 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

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!