Ask Question

What is the Matlab command to create a vector of the even whole numbers between 29 and 73?

+3
Answers (1)
  1. 9 February, 11:50
    0
    x = 29:73;

    x_even = x (2:2:end);

    Explanation:

    In order to create a vector in Matlab you can use colon notation:

    x = j:k

    where j is 29 and k is 73 in your case:

    x = 29:73

    Then you can extract the even numbers by extracting the numbers with even index (2,4,6, etc.) of your vector:

    x_even = x (2:2:end);

    In the line of code above, we define x_even as all the elements of x with even index from index 2 till the end index of your vector, and an increment of 2 in the index: 2,4,6, etc.

    If you want the odd numbers, just use the odd indices of your vector:

    x_odd = x (1:2:end);

    where x_odd contains all the elements of x with odd index from index 1 till the end index, and an increment of 2: 1,3,5, etc.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the Matlab command to create a vector of the even whole numbers between 29 and 73? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers