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

7 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

J. Alex Lee
J. Alex Lee il 7 Ott 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,:);

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by