Clear Filters
Clear Filters

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

2 views (last 30 days)
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

Accepted Answer

CS Researcher
CS Researcher on 2 May 2016
Edited: CS Researcher on 2 May 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;

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!