Question

MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use...

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.

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

  MATLAB CODE

clc;
x=randn(1,10); % Random x matrix
z=[]; % Initilise z matrix
y=[]; % Initilise z matrix
i_z=1; % Staring index for z matrix
i_y=1; % Staring index for y matrix
disp('Initial x matrix is ')
disp(x);

for i=1:10
if(x(i)>0.2) % for x[i] >0.2
z(i_z)=x(i);
i_z=i_z+1; % Increase iterator(index) for y matrix
end
if(x(i)<0.2)
y(i_y)=x(i);
i_y=i_y+1; % Increase iterator(index) for y matrix
x(i)=0; % updating x for x(i)<0.2 as 0
end
end
disp('y matrix is ');
disp(y);
disp('z matrix is ');
disp(z);
disp('New x matrix is ');
disp(x);
  

RESULT:

Initial x matrix is
-1.3499 3.0349 0.7254 -0.0631 0.7147 -0.2050 -0.1241 1.4897 1.4090 1.4172
y matrix is
-1.3499 -0.0631 -0.2050 -0.1241
z matrix is
3.0349 0.7254 0.7147 1.4897 1.4090 1.4172
New x matrix is
0 3.0349 0.7254 0 0.7147 0 0 1.4897 1.4090 1.4172
>>

Add a comment
Know the answer?
Add Answer to:
MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use...
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
  • Chapter 6 Matlab Assignment: Assume x is a row vector containing 100 elements. Write a counter-controlled...

    Chapter 6 Matlab Assignment: Assume x is a row vector containing 100 elements. Write a counter-controlled loop using a "for" command and an "if" command that examines one element of x each time through the loop. If that element is greater than 10, replace it with a random integer between 1 and 20. Chapter 7: Explain the use of functions in computational programs like the ones you wrote

  • Write a MATLAB program to accomplish the following: Create a variable x by assigning it the...

    Write a MATLAB program to accomplish the following: Create a variable x by assigning it the value 5. Then, subtract 8 from the square of x and assign the result to a second variable y. Next, create a vector z containing as values all the positive prime integers greater than or equal to 2 and less than 20. Multiply z by two and subtract y, and assign the result to w. ONLY display the value for w in the Command...

  • MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note:...

    MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note: input values are specified in the function call) Output: calculated maximum value Create a row vector A of values from 50 down to 0, with an increment of 0.5 Multiply the elements of A and the square of the elements of the input vector Store the results in B Find the maximum value of B and store it in C – this is the...

  • using matlab Create the following matrix B. [18 17 16 15 14 13] 12 11 10...

    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...

  • MATLAB Create a row vector vC=2:3:38 that has 13 elements. Then, create the following new vectors...

    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...

  • Q 9 to 12 on matlab Create the following matrix by using vector notation for creating...

    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...

  • Problem 5 Create the following matrix by typing elements explicitly one command. Do not type individual...

    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...

  • Can someone help me to solve it by Matlab? 7. Create a 5 row, 8 col...

    Can someone help me to solve it by Matlab? 7. Create a 5 row, 8 col matrix called mymat w ith random integers betwee n and including 70 and 90 Create a matrix from mymat called newmat whose entries consist of those entries which are both in the second and third rows, but also in the 4th through 6th columns 8. 9 What command would you type to list just the 4th row, 6th column entry of mymat? 1o. Crete...

  • given a row vector x create each of the following row vectors as indicated y is...

    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...

  • Row and columns sum Create a java program that: Input: Receive as input in command line...

    Row and columns sum Create a java program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (m x n) Compute: Compute the sum for each row and store the results in a...

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
ADVERTISEMENT