Question

Given A = [1 2 3;4 5 6;5 4 3], write code to set any value...

Given A = [1 2 3;4 5 6;5 4 3], write code to set any value less than 3 to 0 and any value greater than 3 to 1. On Matlab

Homework Answers

Answer #1
Given A = [1 2 3;4 5 6;5 4 3]

code to set any value less than 3 to 0 and any value greater than 3 to 1
[rows, columns] = size(A);
for i=1:rows
    for j=1:columns
        if(A(i,j)<3)
            A(i,j) = 0;
        elseif(A(i,j)>3)
            A(i,j) = 1;
        end
    end
end

A = [1 2 3;4 5 6;5 4 3];
[rows, columns] = size(A);
for i=1:rows
    for j=1:columns
        if(A(i,j)<3)
            A(i,j) = 0;
        elseif(A(i,j)>3)
            A(i,j) = 1;
        end
    end
end
A

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
Use MATLAB to determine whether the given set of vectors spans R4. (a) {(1, -2, 3,...
Use MATLAB to determine whether the given set of vectors spans R4. (a) {(1, -2, 3, 4), ( 2, 4, 5, 0), ( -2, 0, 0, 4 ), (3, 2, 1, -4)}
let us create a variable for a row vector a = [1, 4, 1, 3, 2,...
let us create a variable for a row vector a = [1, 4, 1, 3, 2, 5, 0] and calculate the mean value of its elements using the Matlab function ‘mean’ and store this value in variable aMean. Fig. 1 gives the Matlab code to do this. a = [1, 4, 1, 3, 2, 5, 0]; aMean = mean(a); Figure 1: Matlab code – row vector and mean of its elements. Let us now construct a row vector b that...
Write code to evaluate the polynomial at the point indicated by using Horner’s algorithm. p(x)=x^5−x^4−3x^3−5x^2+10 at...
Write code to evaluate the polynomial at the point indicated by using Horner’s algorithm. p(x)=x^5−x^4−3x^3−5x^2+10 at x=2 (use MATLAB to code and show the results.)
1: A) Given the following vectorized code: >>x=[1:10]; >>f=x.^2+2; Rewrite this code using a for loop...
1: A) Given the following vectorized code: >>x=[1:10]; >>f=x.^2+2; Rewrite this code using a for loop that defines each element of f one at a time. Make sure to preallocate memory to f before filling each spot. B) See the following code. Rewrite the code in one line using the find function and a For loop. then write it again using a while loop x=[-1 3 7 2 4 0]; v=[]; for i=1:length(x) if x(i)<=2 v=[v, x(i)]; end end please...
Let Y ∼ Unif(1, 5) R1. Write code in R that will simulate the setup in...
Let Y ∼ Unif(1, 5) R1. Write code in R that will simulate the setup in question 3a, and hence, allow you to roughly check your answer. 3a. If you generate 5 random numbers based on Y , what is the probability you’ll get more (numbers greater than 4) than (numbers less than or equal to 4)? R2. Write code in R that will simulate the setup in question 3b, and hence, allow you to roughly check your answer. 3b....
Given: int[][] matrix = new int[5][5] Using the statement above, write a nested loop to set...
Given: int[][] matrix = new int[5][5] Using the statement above, write a nested loop to set matrix as follows: [0] [1] [2] [3] [4] [0] 1 0 0 0 0 [1] 0 2 0 0 0 [2] 0 0 3 0 0 [3] 0 0 0 4 0 [4] 0 0 0 0 5
Following is a preview of the matrix x: Code: [,1] [,2] [,3] [1,] 1 3 5...
Following is a preview of the matrix x: Code: [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 Write the code that return the output: [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [3,] 7 8 9
# Python Given the list values = [], write code that fills the list with each...
# Python Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20 1 4 9 16 25 36 49 64 81 100 0 0 0 0 0 0 0 0 0 0 1 4 9 16 9 7 4 9 11 0 1 0...
Consider the following time series data. Week 1 2 3 4 5 6 Value 18 13...
Consider the following time series data. Week 1 2 3 4 5 6 Value 18 13 16 11 17 14 A) What type of pattern exists in the data? (HORIZONTAL OR TREND) B) Develop a three-week moving average for this time series. Compute MSE and a forecast for week 7. If required, round your answers to two decimal places. Week Time Series Value Forecast 1 18 2 13 3 16 4 11 _______ 5 17 _______ 6 14 _______ MSE:...
Using for loop and if statement, write a MATLAB code to plot a graph for x(t)...
Using for loop and if statement, write a MATLAB code to plot a graph for x(t) as a function of time t in the range 0 to 12 in increment of 0.01 ?(?) = 1: 0 ≤ ? ≤ 1 2? − 1 1 ≤ ? ≤ 2 3 2 ≤ ? ≤ 3 −2.5? + 10.5 3 ≤ ? ≤ 5 −2 5 ≤ ? ≤ 6 4/3 ? − 10 6 ≤ ? ≤ 9 2 9 ≤...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT