How to delete every nth column in table?

조회 수: 8 (최근 30일)
Hanne
Hanne 2024년 3월 11일
편집: Mathieu NOE 2024년 3월 11일
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에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by