How to delete every nth column in table?

9 次查看(过去 30 天)
I have a table (X) and want to delete every 2nd column from it.

回答(1 个)

Mathieu NOE
Mathieu NOE 2024-3-11
编辑:Mathieu NOE 2024-3-11
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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by