MATLAB
Create a row vector vC=2:3:38 that has 13 elements. Then, create the following new vectors by assigning elements of vC to the new vectors: (a) A vector (name it vCodd) that contains all the elements with odd index of vC; i.e., vCodd = 2 8 14 ... 38. (b) A vector (name it vCeven) that contains all the elements with even index of vC; i.e., vCeven = 5 11 17 ... 35. In both parts use vectors of odd and even numbers to address the elements of vC that are assigned to vCodd, and vCeven, respectively. Do not enter the elements of the vectors explicitly.
clc;
clear all;
vC=2:3:38;
Neven=((length(vC)-1)/2);
Nodd=((length(vC))/2)+1;
n=1;
vCodd=zeros(1,Nodd);
for i=1:1:Nodd
vCodd(i)=vC(n);
n=n+2;
end
vCeven=zeros(1,6);
n=2;
for i=1:1:Neven
vCeven(i)=vC(n);
n=n+2;
end
disp('vC=')
disp(vC)
disp('vCodd=')
disp(vCodd)
disp('vCeven=')
disp(vCeven)
Command window:
vC=
Columns 1 through 10:
2 5 8 11 14 17 20 23 26 29
Columns 11 through 13:
32 35 38
vCodd=
2 8 14 20 26 32 38
vCeven=
5 11 17 23 29 35
MATLAB Create a row vector vC=2:3:38 that has 13 elements. Then, create the following new vectors...
given a row vector x create each of the following row vectors as indicated y is two copies of x, one after another (a vector twice as large as x, containing two copies) z is a vector containing the elements of x with odd indices w is identical to x, except it contains the number 0 inserted before the first element of x, a 7 inserted after the fourth element of x, and 12 inserted after the last element of...
Problem 5 Create the following matrix by typing elements explicitly one command. Do not type individual 0 00 0 0 o o 0 0 0 0 0 1 2 3 F=0 01 10 20 0 0 2 8 26 0 0 3 6 32 E 0 045 6 0 0 7 8 9 Problem 6 Create two row vectors: a -4 10 0.5 1.8 -2.3 7, b [0.7 9 -53-0.6 12 (a) Use the two vectors in a MATLAB command...
in c++ 3- Create a vector of integers and do the following: a- Create fillVector function that uses the push_back method provided by the vector class to fill the vector with random numbers (use rand). b- Now implement the void addNumbers(vector &data) method that adds 10 numbers to the data vector (use a for loop). c- Create a new function void print_even(const vector& data) that prints all of the elements in the data vector that are stored at an even...
MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use randn command “x = randn(1,10)). And do the following: a.Test vector x for elements that are less than 0.2. Assign the output to a variable named y. b.Create a variable z that contains the elements in x that are greater than 0.2. c. Modify vector x such that any value in it less than 0.2 is replaced by value 0.
Q 9 to 12 on matlab Create the following matrix by using vector notation for creating vectors with 9 constant spacing and/or the iinspace command. Do not type individual elements explicitly 20 3 в - 4 03 Using the colon symbol, create a 4 x 6 matrix (assign it to a variable named Anine) in which all the elements are the mumber 9. 10Create the following matrix by typing one command. Do not type individual elements explicitly C o o...
using matlab Create the following matrix B. [18 17 16 15 14 13] 12 11 10 9 8 7 6 5 4 3 2 1 Use the matrix B to: (a) Create a six-element column vector named va that contains the elements of the second and fifth columns of B. (6) Create a seven-element column vector named vb that contains elements 3 through 6 of the third row of B and the elements of the second column of B. Create...
Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () function, create a script that generates a row vector (1 row X 20 columns) of random numbers, each with magnitude between 0 and 5 b) (3 pts) Use the round() function to turn all of the values into whole numbers by rounding down (truncate the decimal part on your vector) c) (5 pts) Add code to your script to generate a new vector...
Matlab Question 2. For this problem you have to create a program that defines two vectors of numbers: A and B and uses a for-loop to combine the values of A and B. Note that different parts of the question below specify different orders for combining the elements. To start this exercise start a MATLAB script called q2.m and put, at the top, the vector definition: B [11:20] Question 2a: Problem definition Copy the file q2.m to q2a.m. For this...
2.6) Mathlab Exercise 1. Create a row vector v with values (1, 2, 3, 5, 11, 7, 13). 2. Change the value of the 5th and the 6th element of the v to 7 and 11 respectively. Try doing this with only one command as well. 3. Create a vector Five5 out of all multiples of 5 that fall between 34 and 637. By the way, how many are they? (Tip: look up the command ”length” in help.) 4. Double...
on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A, of matrix A is accesser (3) Correcting an entry is easy to (4) Any submatrix of Ais obtained by d row wise. Rows are separated by semicolons and columns are separated by spaces ner A l 23:45 6. B and hit the return/enter kry matrix A is accessed as A Enter and hit the returnerter key an entry is easy through indesine Enter 19...