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

2 ビュー (過去 30 日間)
Selin Ozdemir
Selin Ozdemir 2016 年 5 月 2 日
コメント済み: Selin Ozdemir 2016 年 5 月 2 日
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 Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by