How can I change/replace values in second column according to conditions?

3 visualizzazioni (ultimi 30 giorni)
Here is the matrix 10x2
1 10
2 24
3 7
4 0
5 18
6 3
7 15
8 2
9 1
10 2
I want to if value in second column is equal 1,2,3,4,13,14,15,16 code will write 1;
5,6,7,8,17,18,19,20 code will write 2;
9,10,11,12,21,22,23,24 code will write 3
and if it is 0, it will write 4. Like this that I want
1 1
2 3
3 2
4 4
5 2
6 3
7 1
8 2
9 1
10 2

Risposta accettata

CS Researcher
CS Researcher il 2 Mag 2016
Modificato: CS Researcher il 2 Mag 2016
Try this:
T = A(:,2);
a = [1,2,3,4,13,14,15,16];
b = [5,6,7,8,17,18,19,20];
c = [9,10,11,12,21,22,23,24];
T(ismember(T,a)) = 1;
T(ismember(T,b)) = 2;
T(ismember(T,c)) = 3;
T(T==0) = 4;
A(:,2) = T;

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by