How to select rows in a table containing both string and numbers?

조회 수: 6 (최근 30일)
Hi everyone,
I'm looking for a method to extract centain rows from a table. The table is loaded form an excel file carried out through the structural analysis software SAP2000. Here a screenshot of the table loaded in MATLAB:
I need to extract the values contained in the colums "Joint", "StepNum", "U1", "U2", "U3". In detail, i need to extract only the rows for the "StepNum" values 1, 2, 8, 9, 11. Furthermore, i'm interested to extract only rows for certain "Joint" values.
The "Joint" rows of interest are:
joints=["2440" "2841" "2989" "S-19" "S-37" "445" "829" "1181" "P-1" "P-3" "447" "831" "1183" "2435" "S-23" "S-41" "2840" "2988" "1476" "1768""2036" "P-2" "P-4" "1478" "1770" "2038" "2442" "S-27" "S-45" "2844" "2992"];
I need something like this:
I tried some struffs but to no avail. I think it is due to cells of the table: "Joints" column contains cells (joints are named using text); the other colums of interest ("StepNum", "U1", "U2", "U3") contains numbers.
Any help or input here would be appreciated!
Thanks in advance!

채택된 답변

J. Alex Lee
J. Alex Lee 2022년 10월 7일
Look up how to index tables, and ismember.
% your table name: modal_displacements
% extract the columns of interest, if you want
% index all rows with ":" and supply column names as a string array
T = modal_displacements(:,["Joint", "StepNum", "U1", "U2", "U3"]);
% filtering criteria
fltr_stepnums = [1,2,8,9,11];
fltr_joints = ["2440" "2841" "2989" "S-19" "S-37" "445" "829" "1181" "P-1" "P-3" "447" "831" "1183" "2435" "S-23" "S-41" "2840" "2988" "1476" "1768""2036" "P-2" "P-4" "1478" "1770" "2038" "2442" "S-27" "S-45" "2844" "2992"];
% row indices meeting criteria
mask = ismember(T.StepNum,fltr_stepnums) & ismember(T.Joint,fltr_joints);
% extract rows meeting the filtering citeria
data =T(mask,:);

추가 답변 (0개)

카테고리

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