Ask Question
16 May, 09:13

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

+1
Answers (1)
  1. 16 May, 12:07
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers