Question

In: Computer Science

Write a MATLAB function that accepts input vector x and returns the number of local maximums...

Write a MATLAB function that accepts input vector x and returns the number of local maximums of x with value between xmin and xmax. Ask user to input values xmin and xmax at the beginning of the procedure. Use vector x (the vector x from that file consists of 1000 numbers ranging from 0.0044 to 0.67).

Solutions

Expert Solution

%% code works in both matlab and octave

%%save below function as num_local_max.m
function nlocalmax=num_local_max(x)
nlocalmax=0;

for i=2:(numel(x)-1)
%%condition for local maximum
if((x(i-1)<x(i)) && (x(i)>x(i+1)))
nlocalmax=nlocalmax+1;
end
end
end

%%end of function


%%run below code in console
%since data is not given creating the random 1000 numbers
%%generate random numbers between 0.0044 and 0.67
nums = (0.67-0.0044)*rand(1,1000) + 0.0044;
num_local_max(nums)


Related Solutions

Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and...
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and returns only the odd index entries. Do this by first setting the even entries to 0, and then removing the 0 entries by using a logical array. The first line of your code should read function p = ReturnOddEntries(p) For example, if you run in the command window p = ReturnOddEntries([1.2 7.1 8.4 -42 100.1 7 -2 4 6]), then you should get p...
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
On Python Write a function that accepts a relative file path as parameter and returns number...
On Python Write a function that accepts a relative file path as parameter and returns number of non-empty lines in the file. Test your function with the provided sample file studentdata.txt.
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Write a MATLAB function named numberWords() that takes a whole number as an argument and returns...
Write a MATLAB function named numberWords() that takes a whole number as an argument and returns a string containing the number word for the whole numbers 0 - 999. For example:  numberWords(234) would return 'two hundred thirty-four' If the input value is not a whole number between 0 - 999 then the function should return a string equivalent to 'ERROR'.
One dimensional dynamic array Write a function that returns the number of integers in an input...
One dimensional dynamic array Write a function that returns the number of integers in an input file stream with the following interface: int findNumber(ifstream &x); Then, use this number to dynamically allocate an integer array. Write another function that reads each number in an input file stream and assign the value to the corresponding array element with the following interface: void assignNumber(ifstream &x, int y[ ]); In your main( ), first open “in.dat” as an input file. Next, apply findNumber(...
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters...
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters in mystring that also occur in the string ‘Python’. Using above function, write a program that repeatedly prompts the user for a string and then prints the number of letters in the string that are also in string ‘Python’. The program terminates when the user types an empty string.
Write a function called HW5_P1 that accepts 1 input argument: an array, a. The function should...
Write a function called HW5_P1 that accepts 1 input argument: an array, a. The function should output an array, b, that is computed as: b=3a+5. Write a MATLAB function called “fit_line” that accepts 2 input arguments: a column vector of x data and a column vector of y data. The nth element in the input arguments should correspond to the nth Cartesian data point i.e. (xn,yn). The function should compute and return 2 outputs: the slope, m, and the y...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input #...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input # of rows: 2 Input Row 1: 9 8 7 6 3 2 1 5 4 Input Row 2: 1 2 4 3 5 6 9 8 7 Output 1,2,3,4,5,6,7,8,9 1,2,3,4,5,6,7,8,9
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT