Question



A = randi(6, 7); %creates a 2D array with 6 rows %with random integers sz = size(A); for i = 1:sz(1) for j = 1:sz (2) if rem(
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

A = randi(6, 7);

sz = size(A);

A(:, 2:2:(sz(2)-1)) = 0 %YOUR ANSWER

Explanation:

In vectorized code we access all even column and assign them to zero

Add a comment
Know the answer?
Add Answer to:
A = randi(6, 7); %creates a 2D array with 6 rows %with random integers sz =...
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
  • Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The...

    Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The first row has length 1, the second row has length 2, the third row has length 3, and so on. Then initialize the array using nested for loops so that the value of A[i][j] is i+j. Finally, print out the array in a nice triangular form.

  • The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi...

    The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi and n, and retums two output arguments: a row vector of n2 elements and and n-by-n matrix. The two output arguments must contain the exact same set of random integers that fall between 1 and maxi Do this using the random number genertor, not by reshaping the data Example n,v-randi...

  • Use the following code, which initializes an array x with 1000 random integers, to answer the...

    Use the following code, which initializes an array x with 1000 random integers, to answer the questions a and b. java.util.Random generator = new java.util.Random( );//accessing Random class final int MAX = 1000; int[] x = new int[MAX]; for( int j = 0; j < MAX; j++ ) { x[j] = generator.nextInt( MAX ) + 1; } a. Write partial code to print all array elements of x in reverse order (one array element per line) b. Write partial code...

  • Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std;...

    Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std; int main(){    int rows = 5; int cols = 5; int x;    int** arr = new int[rows][cols]    cin >> x; arr[x][x] = x; cout << "arr[x][x] = " << arr[x][x];    return 0; } Question 2: Fix the code to initialize the 2D array elements to x #include <iostream> using namespace std; int main(){    int rows; int cols; int x;...

  • whats the answers How many total integers elements are in an array with 4 rows and...

    whats the answers How many total integers elements are in an array with 4 rows and 7 columns? 07 28 11 What is the resulting array contents, assuming that itemList is an array of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList[i] - i; -54,0, 1, 10 O 0, 1, 2, 3 O 1, 2, 3, 4 O-55,-1, 0,9 Given an integer array myVals of size N_SIZE (i.e. int[] myVals...

  • in java / You will: // 1- create a square 2 dimensional array of random size...

    in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • In C++ for 2D Array: Write a program that uses a function that manipulates a 2D...

    In C++ for 2D Array: Write a program that uses a function that manipulates a 2D array of integers as follows: 1. Fill the first row and column in the array with random bits 2. Every subsequent cell should be filled as follows: 1. If the cells that are to the left and top of it are equal, then you should store their sum in it b. Otherwise, your program should store the highest among them. Test your function using...

  • Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and...

    Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and also outputs the second row. The input arguments: • inArray: A double precision 2D array of size nxn, where n is at least 3. The output arguments: outArray: A double precision 2D array of size nxn that is a copy of inArray except with the corners set to zero. • secondRow: A double precision 1D array of size n. This is the second row...

  • C++ program Write a program which: 1. Enters data into the 2D array of integers which...

    C++ program Write a program which: 1. Enters data into the 2D array of integers which is 5x5 The data should be entered with an assignment statement using nested for loops that is do not scan in the data. The data should be: 1 2 4 8 16 1 3 9 27 81 1 4 16 64 256 1 5 25 125 625 1 6 36 216 1296 2. Print out the following using a nested for loop Row 0:...

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