Replaces data in a matrix with Matlab

56 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

Very simple, just use the following command.

B=(A<=1).*A+(A>1).*2

Some additional comments: A<=1 generates a 0/1 matrix of the same size as A which is equal to 1 whenever the the respective entry of Ais $\leq1$. A>1 works accordingly.