Clear Filters
Clear Filters

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

10 views (last 30 days)
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!

Accepted Answer

J. Alex Lee
J. Alex Lee on 7 Oct 2022
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,:);

More Answers (0)


Find more on Characters and Strings in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!