I'd like to remove variables (columns) containing specifc name

조회 수: 17 (최근 30일)
Jinho Lee
Jinho Lee 2023년 5월 16일
답변: Image Analyst 2023년 5월 17일
Hello,
I have a kind of big data table (eg. 300 variables) and I'd like to sort out the table by removing variables.
I imported csv file and it has variable names showing the pattern such as xxxx_A or yyyy_B
So I tried to use removevars function to remove all columns containing '_B' but failed
Actually I am not sure how to determine specific variables
I'd appreciate if anyone can help to sort out the table by specific column name
Thanks

답변 (2개)

Matt J
Matt J 2023년 5월 16일
편집: Matt J 2023년 5월 16일
One way,
idx=contains(T.Properties.VariableNames,"_B" | "_A"); %T is your table
T(:,idx)=[];

Image Analyst
Image Analyst 2023년 5월 17일
Try this:
% Create sample table.
rows = 5;
xxxx_A = 1:rows;
yyyy_B = rand(rows, 1);
col3 = rand(rows, 1);
t = table(xxxx_A(:), yyyy_B(:), col3, 'VariableNames', {'xxxx_A', 'yyyy_B', 'col3'})
t = 5×3 table
xxxx_A yyyy_B col3 ______ _______ _________ 1 0.14283 0.96762 2 0.932 0.0085996 3 0.10426 0.73839 4 0.65724 0.56634 5 0.46341 0.17621
% Now remove the column called "yyyy_B"
t = removevars(t, 'yyyy_B')
t = 5×2 table
xxxx_A col3 ______ _________ 1 0.96762 2 0.0085996 3 0.73839 4 0.56634 5 0.17621

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by