How to delete every nth column in table?

7 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by