Question

Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and also outputs the second row. The
Function Save e Reset MATLAB Documentation 1 function CoutArray, secondRow] = ZeroCorners SecondRow(inArray) % insert your co
0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [outArray, secondRow] = ZeroCornersSecondRow(inArray)

    % compute size n of array

    n =size(inArray,1);

    % copy inArray to outArray

    outArray=inArray;

    % copy second row

    secondRow=inArray(2,:);

    % set first element of first row to 0

    outArray(1,1) = 0;

    % set last element of first row to 0

    outArray(1,n) = 0;

    % set first element of last row to 0

    outArray(n,1) = 0;

    % set last element of last row to 0

    outArray(n,n) = 0;

end

.

testing.m:

inArray=[5 2 3;

3 3 5;

1 4 6];

[outArray, secondRow] = ZeroCornersSecondRow(inArray)

.

Output:

outArray II 2 3 3 5 4 secondRow 3 35

.

Add a comment
Know the answer?
Add Answer to:
Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and...
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
  • 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...

  • USING C++: Write a function that given a 2D dynamic array of integers, will return the...

    USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...

  • Need help with a 2D list - I'm almost there! #Write a function called check_winner which...

    Need help with a 2D list - I'm almost there! #Write a function called check_winner which takes #as input a 2D list. It should return "X" if there are four #adjacent "X" values anywhere in the list (row, column, #diagonal); "O" if there are four adjacent "O" values #anywhere in the list; and None if there are neither. # #Here are the ways Connect-4 is different from tic-tac-toe: # # - Connect-4 is played with 6 rows and 7 columns...

  • Please code using C++ Thank you Write a function that receives a 2d array of type...

    Please code using C++ Thank you Write a function that receives a 2d array of type double and returns the average of all elements in the 2d array

  • Iterating over a 2D array If we want to visit or process every element of a...

    Iterating over a 2D array If we want to visit or process every element of a 2D array, we need a nested for loop to do it. Generally, when you iterate over a 2D array, you want to do it in row major order, because this is more memory efficient. The reason why is that adjacent elements in a row are stored contiguously (one after another) in memory. Another reason, for an English speaker, is that this is the same...

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

  • Write a function named stats, that takes an array and the number of elements in the...

    Write a function named stats, that takes an array and the number of elements in the array as arguments. It must compute and print the minimum value in the array, maximum value in the array and the average value of all the values inside the array. Your function MUST be named stats Your function has two parameters in the following order: an array of type double The number of elements in the array, type int Your function should NOT return...

  • The last element in each array in a 2D array is incorrect. It’s your job to...

    The last element in each array in a 2D array is incorrect. It’s your job to fix each array so that the value 0 is changed to include the correct value. In the first array, the final value should be the length of the first array. In the second array, the final value should be the sum of the first value, and the second to last value in the array. In the third array, the final value should be the...

  • Write a C++ program that uses a two dimensional array to display a table of probabilities...

    Write a C++ program that uses a two dimensional array to display a table of probabilities for a pair of rolling dice. Your custom assigned range of values of each die are: 5 up to and including 10. Section 1 of Program - Specifications: The top row of the table, left to right, and the left column of the array, top to bottom, must contain the assigned range of values displayed on each of the die in ascending order populated...

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