MATLAB 2019
The main function will have exactly one input and exactly one output. Using best practices, check the number of input arguments as well as the type of input.
This function should only accept a vector (row or column). This also means that the value COULD be a scalar value. This function should accept scalars as well. The vector should be numeric, but can be any value: positive or negative, whole number or rational number.
Throw a descriptive error if these conditions are not met.
Question!: How do you create a function and make sure the user inputs the correct type of value into it? In this case, how do you make sure that the function only accepts a vector with numbers in it?
Please provide the specific code in MATLAB 2019.
Matlab code is:
==============================================================================
%% function to check input argument and output argument scalar
vector
function [output] = CheckRequirement(input)
%%% nargin checks number of input argument
switch nargin
case 1
fprintf('Number of input argument is 1...\n');
output = "input is correct";
otherwise
fprintf('Number of input argument is not 1\n');
return;
end
%%% nargout checks number of output argument
switch nargout
case 1
fprintf('Number of output argument is 1\n');
output = output+ ";output is correct";
otherwise
fprintf('Number of output argument is not 1\n');
return;
end
%%% checking whetger input is scalar or vector
check = isscalar(input);
switch check
case 1
if isnumeric(input)==1%% scalar is numeric or not
fprintf('input is scalar and numeric\n');
else
fprintf('input is scalar and not numeric\n');
end
case 0
if isnumeric(input)==1%% vector is numeric or not
fprintf('input is vector and numeric\n');
else
fprintf('input is vector and not numeric');
end
end
end
============= screenshots of the code and the output===============================



========================== end of the explanation ===================================
============= PLEASE LIKE THE POST========================
%% function to check input argument and output argument scalar vector function (output] = CheckRequirement (input) %%% nargin checks number of input argument switch nargin case 1 fprintf('Number of input argument is 1...\n'); output = "input is correct"; otherwise fprintf('Number of input argument is not i\n'); return; end %%% nargout checks number of output argument switch nargout case 1 fprintf('Number of output argument is i\n'); output = output+ ";output is correct"; otherwise fprintf('Number of output argument is not 1\n'); return; end %%% checking whetger input is scalar or vector check = isscalar (input); switch check case 1
ULUL 1 fprintf('input is scalar and numeric\n'); else fprintf('input is scalar and not numeric\n'); end case o if isnumeric (input) ==1%% vector is numeric or not fprintf('input is vector and numeric\n'); else fprintf('input is vector and not numeric'); end end end
>> out = CheckRequirement ([6 7 8 9]) Number of input argument is 1.... Number of output argument is 1 input is vector and numeric out = "input is correct;output is correct" >> out = CheckRequirement (4) Number of input argument is 1... Number of output argument is 1 input is scalar and numeric out = "input is correct;output is correct" >> out = CheckRequirement () Number of input argument is not 1 Output argument "output" (and maybe others) not assigned during call to "CheckRequirement".
MATLAB 2019 The main function will have exactly one input and exactly one output. Using best...
Needs to be in MATLAB.
Create a function that accepts two numbers as input arguments and returns one with the larger absolute value. The function must return an error message if the number of arguments is not 2.
matlab
The error function is a mathematical function that frequently arises in probability and statistics. It also can show up in the solution to some partial differential equations, particularly those arising in heat and mass transfer applications. The error function is defined as 2 e-t dt picture attached This function is actually built-in to MATLAB as the command erf, and here we'll use that function to compute a "true value" with which we can compare results of two interpolation approaches....
Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...
Please write the code using matlab
1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...
use matlab to solve it
1. Write a function called MyTimeConversion with the following function declaration line. begin code function [Hours, Minutes, Message] = MyTimeConversion (TotalMinutes) end code The input argument TotalMinutes should be a nonnegative scalar integer representing the total number of minutes in a specified time interval. The output arguments Hours and Minutes should be nonnegative scalars such that Hours*60 + Minutes = TotalMinutes and the value of Minutes must be less than 60. The output argument Message...
Write a MATLAB function named top5_temps The function will have one input and two return values The input will be a list of temperatures recorded every minute in an electric arc furnace (for at least 6 minutes) The first return value of the function should be the number of datapoints in the list (number of minutes of data) The second return value should be a single value that is the average temperature for the 5 highest temperatures. Notes: Example Test...
In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...
[MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...
1. (10 pts) Write a function called hws_problem1 that accepts three input arguments: 1) a 3-column string matrix (say names), 2) a 4-column numeric matrix (say, numbers), and 3) a scalar threshold value (say, threshold). Note that the names matrix is the new string type that uses double quotes. The first two input arguments contain information about U.S. astronauts, where each corresponding row of the two matrices represents a single astronaut. The columns of the two matrices contain the following...
This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...