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

2 次查看(过去 30 天)
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

采纳的回答

CS Researcher
CS Researcher 2016-5-2
编辑:CS Researcher 2016-5-2
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by