Question

Matlab. Write a function with header [N]=myNOdds(A), where A is one-dimensional array of doubles and N...

Matlab. Write a function with header [N]=myNOdds(A), where A is one-dimensional array of doubles and N is the number of odd numbers in A.

Test Cases: >>n1=myNOdds([1:100])

n1=

50

>> n2 = myNOdds ([2:2:100])

n2=

0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function N = myNOdds(A)
    N = 0;
    for i=1:length(A)
        if(mod(A(i),2)==1)
            N = N + 1;
        end
    end
end

Add a comment
Know the answer?
Add Answer to:
Matlab. Write a function with header [N]=myNOdds(A), where A is one-dimensional array of doubles and N...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB function Write an efficient function, f(v) that takes a one-dimensional array of length N^2 for...

    MATLAB function Write an efficient function, f(v) that takes a one-dimensional array of length N^2 for a square matrix (in a row-vectorized form) as an input and returns the trace of the matrix.

  • Do the following: - Write and test a function that takes an array of doubles and...

    Do the following: - Write and test a function that takes an array of doubles and returns the average of the values in the array - Write and test a function that takes an array of doubles and returns number of values in the array that are above the average of the values in the array - Write and test a function that takes an array of Strings and returns number of values in the array that start with an...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • in matlab (a)Write a function to generate n random integers between -b and b. (b) Using...

    in matlab (a)Write a function to generate n random integers between -b and b. (b) Using the function you wrote in (a) generate 50 random numbers in a vector A where b = 100; (c) This array A will contain both negative, positive and possibly zero entries. Write a MATLAB script to compute the percentage of positive, negative and zero entries in the array.

  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • array function • Create a function called show2D. • This function should accept a two-dimensional array...

    array function • Create a function called show2D. • This function should accept a two-dimensional array as parameter and display its contents that are odd numbers on the screen. • This function should work with any of the following arrays of different sizes: int hours[3][9]; int stamps[7][9]; int cities[15][9]; • Write a demo program to show how to use the function show2D. this is c++ program Task 2: Array functions • Create a function called show2D. • This function should...

  • Write a function with header [d] = myIEEE2Dec(IEEE) Write a function with header [d]=myIEEE2Dec (IEEE), where...

    Write a function with header [d] = myIEEE2Dec(IEEE) Write a function with header [d]=myIEEE2Dec (IEEE), where IEEE is a 1 * 32 array of ones and zeros representing a 32-bit IEEE754 number. The output should be d, the equivalent decimal representation of IEEE. The input variable IEEE will always be a 32-element array of ones and zeros defining a 32-bit single precision float.

  • Write a java Program Initialize Array. Write a Java method initArray() with the following header to...

    Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • MATLAB Write a function with the header function [s, count] = myMonteCarlo(f, xLeft, xRight, tol) which uses bracketing...

    MATLAB Write a function with the header function [s, count] = myMonteCarlo(f, xLeft, xRight, tol) which uses bracketing logic and random numbers to solve for the root of f. Start from your code for Problem 1, then modify the update equation to randomly choose a number between xLeft and xRight. That is your xNew. Note your code will take a different number of iterations to find the root every time you run it, even for the exact same initial bracket,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT