How to delete every nth column in table?

22 views (last 30 days)
Hanne
Hanne on 11 Mar 2024
Edited: Mathieu NOE on 11 Mar 2024
I have a table (X) and want to delete every 2nd column from it.

Answers (1)

Mathieu NOE
Mathieu NOE on 11 Mar 2024
Edited: Mathieu NOE on 11 Mar 2024
maybe this ?
X = (1:9)'*(1:10:50);
% remove only 2nd column
t = array2table(X,'VariableNames',{'t' 'x' 'y' 'z' 'r'})
t = 9×5 table
t x y z r _ __ ___ ___ ___ 1 11 21 31 41 2 22 42 62 82 3 33 63 93 123 4 44 84 124 164 5 55 105 155 205 6 66 126 186 246 7 77 147 217 287 8 88 168 248 328 9 99 189 279 369
t(:,2) = []
t = 9×4 table
t y z r _ ___ ___ ___ 1 21 31 41 2 42 62 82 3 63 93 123 4 84 124 164 5 105 155 205 6 126 186 246 7 147 217 287 8 168 248 328 9 189 279 369
% remove every 2nd column (c = 2,4,6,...)
t = array2table(X,'VariableNames',{'t' 'x' 'y' 'z' 'r'});
t(:,2:2:end) = []
t = 9×3 table
t y r _ ___ ___ 1 21 41 2 42 82 3 63 123 4 84 164 5 105 205 6 126 246 7 147 287 8 168 328 9 189 369

Categories

Find more on Tables 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!