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

Assignment Help:

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


Related Discussions:- Generate a matlab error with a descriptive error message

Illustration of for loop, illustration of for loop: illustration, to p...

illustration of for loop: illustration, to print a column of numbers from 1 to 5: for i = 1:5 fprintf('%d\n',i) end   This loop can be entered in the Command Wi

Illustration of script documentation, Illustration of script Documentation:...

Illustration of script Documentation: For illustration, the script to compute the area of a circle could be modified to have comments: The first comment at the startin

Error in variables statements, Error in variables statements: Error: T...

Error in variables statements: Error: The expression in the left of equals sign is not a valid target for an assignment. >>  By placing a semicolon at the end of the sta

Pre- dicting and plotting., You will need to implement at least two Matlab...

You will need to implement at least two Matlab functions: HW3main.m and svmTrain.m. The implementation details are as follows: function [alpha] = svmTrain(X,T,kernel,C,sigma) %

Financial computing with matlab project, This project carries 50% of your ?...

This project carries 50% of your ?nal mark. Please hand in your work to the Mathematical and Physical Sciences School O?ce, no later than 4pm Monday 21st January 2013. Please ?l

Simulation of a pn junction, would you please send the programing code simu...

would you please send the programing code simulation.

#title.matrix, #defining matrix using only special commands

#defining matrix using only special commands

Develop a matlab program to design algorithm, Write a pseudo-code showing t...

Write a pseudo-code showing the list of steps to take for solving the given problem. In this process, you should identify the functions that are to be used in the program. Develop

Calculate the signal-to-noise ratio, Use the MATLAB randn function to gener...

Use the MATLAB randn function to generate 1000 points for x. Generate the output of the unknown system with the ?lter function and b=[1232 1] and a=[1]. Normalise the ?lter output

Mri - detecting defects in major ateries, MRI (magnetic resonance imaging) ...

MRI (magnetic resonance imaging) scanners allow doctors to now obtain complete body images for medical diagnosis purposes. The system produces scans which represent slices through

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd