Question

In: Computer Science

MATLAB QUESTION: I have to write a function that pretty much cleans number. these are the...

MATLAB QUESTION:

I have to write a function that pretty much cleans number.

these are the instructions

Inputs:

number1 - a 1d of array of number, size doesn't matter

outputs:

number2 - all number in number1 that are 0 need to be set to nan and return via number2.

data - storing the number of 0's in number1 that pretty much are being set to nans

here's the code:

function [number2, data] = cleanNumber(number1)

%add your code below..

end

code to call your function

rebuild = [ 205,201,198,0,197,210,220,199,0186,188];

disp("before cleaning numbers:")

disp(rebuild)

rebuild = cleanNumber(rebuild);

disp("after cleaning numbers:")

disp(rebuild)

Solutions

Expert Solution

Here is the function.

function [number2, data] = cleanNumber(number1)

    number2=number1;          % store the number1 in number2
    number2(number2==0)=nan;  % change the numbers with 0s to NaN
    data = sum(number1==0);   % finding the number of 0s

end

Running code for given conditions.

rebuild = [ 205,201,198,0,197,210,220,199,0186,188];

disp("before cleaning numbers:")

disp(rebuild)

rebuild = cleanNumber(rebuild);

disp("after cleaning numbers:")

disp(rebuild)

Output



before cleaning numbers:
   205   201   198     0   197   210   220   199   186   188

after cleaning numbers:
   205   201   198   NaN   197   210   220   199   186   188


Related Solutions

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....
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
Write a new MATLAB function as described in the following: 1. The new function will have...
Write a new MATLAB function as described in the following: 1. The new function will have three input parameters: f, W, C. 2. Parameter f will specify the frequency of the square wave. 3. The parameter W will specify the width of the single pulse as a number of sample periods. 4. The parameter C will specify the number of square wave cycles. 5. Calculate a number of samples, N, to run the simulation for both waveforms. 6. Create one...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits and the multiplication of the digits. The input of this function is N (entered number) and the outputs are number_digits and sum_digits.
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'.
Write and submit at a Matlab function that sums up a specified number of odd-power terms...
Write and submit at a Matlab function that sums up a specified number of odd-power terms from the Maclaurin series of sin(x)  using following function format function s = etaylor(x, n) % Sum of first n non-vanishing terms of Maclaurin series of sin(x) % For example, etaylor(0.5, 1) should be 0.5, and etaylor(0.5, 2) should be 23/48   
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).
In MATLAB write a function secant.m to apply the secant method. function [x,i] = secant(f, x0,...
In MATLAB write a function secant.m to apply the secant method. function [x,i] = secant(f, x0, x1, tol, maxiters) [x,i] = secant(f, x0, x1, tol, maxiters) performs the secant method with f(x), starting at x_0 = x0 and x_1 = x1, and continuing until either |x_i+1 - x_i| <= tol, or maxiters iterations have been taken. The number of iterations, i, is also returned. An error is raised if the first input is not a function handle. A warning is...
I have the following question: Write a recursive function to find the Nth element from the...
I have the following question: Write a recursive function to find the Nth element from the top of a stack. For example, if N is 3 the function should return the third element in the stack. Use the following header: template <class Type> Type getNth( stack<Type> & s, int n) Although your function may push and pop values from the stack, it must eventually leave the stack in its original state. Your function may NOT use a help stack or...
I need to write a function that counts the number of total wins and losses. I...
I need to write a function that counts the number of total wins and losses. I have a text file called analysis_data.txt with 1000 lines written Won Loss Won Loss Won Won ... The function need to do the following: Opens the analysis_data.txt file and reads through all the data, counting number of 'Won' and 'Loss' words stored in the file. Returns two integers: count of wins and count of losses from the text file. **Can't use the break statement
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT