A is a matrix (6 ×6) defined as:
A= [0.25 0.35 0.46 0.56 0.67 0.78;
0.25 0.37 0.49 0.61 0.73 0.86;
0.25 0.38 0.52 0.66 1.80 1.94;
0.25 0.40 0.55 0.71 1.86 1.92;
0.25 0.42 0.59 1.76 1.93 1.96;
0.25 0.43 1.62 1.81 1.98 1.99]
I want to create a matrix B with the same variables as the data set of the matrix A, but replace the data that is greater than 1 by the number 2.
Very simple, just use the following command.
B=(A<=1).*A+(A>1).*2Some additional comments:
A<=1generates a 0/1 matrix of the same size asAwhich is equal to 1 whenever the the respective entry ofAis $\leq1$.A>1works accordingly.