Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

CS Researcher
CS Researcher am 2 Mai 2016
Bearbeitet: CS Researcher am 2 Mai 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;

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by