Question

create a m.file function in Matlab that ask which element of the magic matrix to replace...

create a m.file function in Matlab that ask which element of the magic matrix to replace then replaces it.

Homework Answers

Answer #1

function x = replace(x) %function that takes magic matrix as argument and return modified matrix

a=input("which element of the magic matrix to replace: ");

b=input("with what to replace the element: ");

x(x==a)=b; %replacing elements of given magic matrix

end

function x = replace(x)              %function that takes magic matrix as argument and return modified matrix
    a=input("which element of the magic matrix to replace: ");
    b=input("with what to replace the element: ");
    x(x==a)=b;                    %replacing elements of given magic matrix 
end
Know the answer?
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
Similar Questions
Write MATLAB code to create a 5x5 matrix A with 2's on the diagonal, and -1...
Write MATLAB code to create a 5x5 matrix A with 2's on the diagonal, and -1 on the super- and sub-diagonal. Then replace the (1,1) element of A with a 1. (Make your commands capable of handling an arbitary sized NxN matrix by first defining N=5, then using the variable N as the size in each of the commands.)
Exercise 1: Write MATLAB code to create a 5x5 matrix A with 2's on the diagonal,...
Exercise 1: Write MATLAB code to create a 5x5 matrix A with 2's on the diagonal, and -1 on the super- and sub-diagonal. Then replace the (1,1) element of A with a 1. (Make your commands capable of handling an arbitary sized NxN matrix by first defining N=5, then using the variable N as the size in each of the commands.)
**Please use MATLAB** 11)Function: Create a function that takes inputs “x” and “z” and generates any...
**Please use MATLAB** 11)Function: Create a function that takes inputs “x” and “z” and generates any random matrix of dimension “x” or “z”, whichever is larger. 12)Function: Create a function that takes a generic matrix, x, and finds the smallest value in the matrix. The function must work for matrices of any size or dimension. **Please use MATLAB** Also, please include code used for the function. I have tried several times but have been unsuccessful.
In the code space provided in Matlab Grader, create a function that: 1. Accepts an input...
In the code space provided in Matlab Grader, create a function that: 1. Accepts an input matrix A as its only input argument. Matrix A is a 3x3 matrix of random integers between 1 and 4 2. Produces and output matrix B as its only output argument. Matrix B will also be a 3x3 matrix. 3. Calculates the elements of matrix B such that: a. the values of B along the diagonal are equal to the respective elements in A...
Create a function x=backsub(U,y) in matlab that accepts as input arguments a nxn matrix U and...
Create a function x=backsub(U,y) in matlab that accepts as input arguments a nxn matrix U and n-vector y, and returns as output a column vector x consisting of the values of the unknowns x1; x2; : : : ; xn.
MATLAB:: Create a matrix with one through 15 on the diagonal. First create a one row...
MATLAB:: Create a matrix with one through 15 on the diagonal. First create a one row 15 column matrix with 1 through 15 in it. Then use the “diag” command .
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its...
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its sole input. If the assumption is wrong, the function returns an empty matrix. Otherwise, the function doubles every odd element of A and returns the resulting matrix. Notice that the output matrix will have all even elements. For example, the call B = matrix_problem([1 4; 5 2; 3 1], will make B equal to [2 4; 10 2; 6 2]. The function should work...
Write a code in matlab for going through every element in a imported image matrix that...
Write a code in matlab for going through every element in a imported image matrix that has been gray scaled using for loops (going through every row and column) and changing every element that is equal to 255 to 1 and every number less then 255 equal to 0. Then find the x and y coordinate of each element now equal to 0 in that image matrix once again going through each row and column.
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is...
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is equal to the sum of its row and column number, except for the diagonal elements which are zeros
create program using matlab, that displays number of (+) entries (=>0) in matrix and number of...
create program using matlab, that displays number of (+) entries (=>0) in matrix and number of negative (<0). Hard code matrix in program. Use nested loops and an if-else-end structure to count (+) and (-) entries. Program should display original matrix and number of positive/negative entries.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT