Effacer les filtres
Effacer les filtres

Reverse the value in multiple columns

1 vue (au cours des 30 derniers jours)
Jinah Lee
Jinah Lee le 16 Mai 2017
Modifié(e) : James Tursa le 16 Mai 2017
Hello, I have 564*31 matrix, and I have inverse the values in column 6,24,35,and 46. Values in these columns are 1,to 5 and I have reverse them. For example, I need to reverse 1 to 5, 2 to 4, 3 becomes 3, 4 to 2 and 5 to 1 in these column. How can I approach?
Thank you so much!

Réponses (1)

James Tursa
James Tursa le 16 Mai 2017
Modifié(e) : James Tursa le 16 Mai 2017
x = your matrix
c = a vector with column numbers to reverse
x(:,c) = 6 - x(:,c);
e.g.,
>> x = randi(5,6,6) % <-- some sample data
x =
1 2 2 1 5 3
4 4 5 3 5 5
2 4 1 1 1 1
3 4 5 5 2 2
1 3 3 1 2 1
4 1 5 4 5 1
>> c = [1 3 6] % <-- columns to work on
c =
1 3 6
>> x(:,c) = 6 - x(:,c)
x =
5 2 4 1 5 3
2 4 1 3 5 1
4 4 5 1 1 5
3 4 1 5 2 4
5 3 3 1 2 5
2 1 1 4 5 5

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by