Generate a matlab error with a descriptive error message, MATLAB Programming

Write a function called threshold2 (in a file called 'threshold2.m'). The function takes an arbitrary number of input variables. The first input variable, t, is required and is the threshold value. The remaining arguments are arbitrarily sized arrays. The function should return the same number of output variables as there are input arrays to threshold.

Each of the output variables should have the same elements as the corresponding input variable, except in every position where an input value is less than or equal to the threshold t, there should be a 0.

If the user doesn't specify enough output variables when calling this function, the function should generate a MATLAB error with a descriptive error message.

If the user doesn't specify enough input variables to fill all of the output variables requested, the remaining output variables should be set to NaN and a warning messaging (just using disp) should be displayed by the function.

Sample runs of this program might look like this:

>> z = 1:5;

>> a = threshold2(3,z)

a =  0 0 0 4 5

>> y = 1:6;

>> [a b] = threshold2(4,z,y)

a =  0 0 0 0 5

b =  0 0 0 0 5 6

>> [a b c] = threhold2(4,z,y)

a = 0 0 0 0 5

b =  0 0 0 0 5 6

c =  NaN

>> a = threshold2(4,z,y)

?? Error using ==> threshold2

Not enough output variables.

Be sure to properly comment your code.

From within 'hw4.m' write a series of expressions that demonstrate the threshold2 function being executed on at least three different sets of non-error generating input. Be sure to demonstrate the case when more ouput variables are present than corresponding input variables.

Finally, execute the threshold2 function with a threshold value plus three input variables but set it equal to only two output variables. Catch the error that your function should have generated such that the script doesn't stop executing and extract the message that was associated with that error. Use the display function to display the error message and then set all of the original output variables equal to NaN

Posted Date: 3/22/2013 7:06:57 AM | Location : United States

Related Discussions:- Generate a matlab error with a descriptive error message, Assignment Help, Ask Question on Generate a matlab error with a descriptive error message, Get Answer, Expert's Help, Generate a matlab error with a descriptive error message Discussions

Write discussion on Generate a matlab error with a descriptive error message
Your posts are moderated
Related Questions
Why Function stubs are used?

how to write the national log (ln(x)) in matlap ?

Create a GUI that has A button to bring up a dialog to select a text file and read it in. Plot the x,y values on the GUI Have text entry values, one for each parameter, in which

The cost of sending a package by an express delivery service is $15 for the first two pounds, and $4.25 for each pound over two pounds. Write a program that computes the cost of

function y=tps(r) % This is the thin-plate spline if r  y=0; else  y=r^2*log(r); end function y=fun(point) % my target function x=point(1); z=point(2); y=7-4*x^2+z^3;

draw midpoint circle by matlab

Illustration to logical function: In addition to such logical operators, the MATLAB also has a function xor, that is the exclusive or function. It returns the logical true if

Order of precedence: As with the numerical operators, it is significant to know that the operator precedence rules. Table below shows the rules for the operators which  have b

An FIR filter has coefficients b = [ 1.0000   -0.6387    1.0214    0.8210   -0.7470    1.0920 ] (a) Find H(z) for the filter and plot its frequency response (magnitude and phase

Writing data to a File: The save function can be used to write a data from the matrix to the data file, or to append a data file. The format is as shown below: save filenam