How te delete certain coulmns from a table with respect to the header

조회 수: 3 (최근 30일)
Mustafa Sobhy
Mustafa Sobhy 2022년 4월 16일
답변: Voss 2022년 4월 16일
I need to delete all (AA) columns from a huge table like this
AA B AA B C .. G
1 1 1 1 1 .. 1
3 0 2 5 6 .. 5
4 5 8 9 6 .. 0
0 2 8 8 7 .. 2
Thanks in advance!

답변 (1개)

Voss
Voss 2022년 4월 16일
I'm unable to create a table with more than one column called 'AA'
AA = [1; 3; 4; 0];
B = [1; 0; 5; 2];
table(AA,B,AA)
ans = 4×3 table
AA B AA_1 __ _ ____ 1 1 1 3 0 3 4 5 4 0 2 0
So I'll assume you have a cell array:
T = {'AA' 'B' 'AA' 'C'; 1 1 1 1; 3 0 2 6; 4 5 8 6; 0 2 8 7}
T = 5×4 cell array
{'AA'} {'B'} {'AA'} {'C'} {[ 1]} {[1]} {[ 1]} {[1]} {[ 3]} {[0]} {[ 2]} {[6]} {[ 4]} {[5]} {[ 8]} {[6]} {[ 0]} {[2]} {[ 8]} {[7]}
% now delete the columns of T whose element in the first row is 'AA':
T(:,strcmp(T(1,:),'AA')) = []
T = 5×2 cell array
{'B'} {'C'} {[1]} {[1]} {[0]} {[6]} {[5]} {[6]} {[2]} {[7]}

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by