How to get specified data in table

Please help me.
How can i filter the table by specified 'Pushover-x' as a rownames and only vartype 'StepNum' , 'GlobalFX', 'GlobalFZ' data which i want to get.

 採用された回答

Stephen23
Stephen23 2024 年 2 月 19 日
編集済み: Stephen23 2024 年 2 月 19 日

0 投票

Where T is your table:
idx = strcmpi(T.OutputCase,'Pushover-x');
out = T(idx,{'StepNum','GlobalFX','GlobalFZ'})
Note that if OutputCase really were the RowNames then you could have done this:
out = T('Pushover-x',{'StepNum','GlobalFX','GlobalFZ'})

6 件のコメント

Arif
Arif 2024 年 2 月 19 日
hey thanks a lot. I've learned from you. But what if i want multiple filter ? I already did but i think it is not shortway. Do you have any idea, how to make it simple ?
this is my code :
jointdisplacement = array2table(TableData,"VariableNames",FieldKeysIncluded)
idx = strcmp(jointdisplacement.Joint,'5')
out = jointdisplacement(idx,{'OutputCase','StepNum','U1'})
idx2 = strcmp(out.OutputCase,'Pushover-x')
out2 = out(idx2,{'StepNum','U1'})
Stephen23
Stephen23 2024 年 2 月 19 日
編集済み: Stephen23 2024 年 2 月 19 日
"But what if i want multiple filter ?"
You can combine multiple logical vectors using &. For example where T is your table:
idx = strcmp(T.Joint,'5') & strcmp(T.OutputCase,'Pushover-x');
out = T(idx,{'StepNum','U1'})
Arif
Arif 2024 年 2 月 20 日
thanks a lot
Arif
Arif 2024 年 2 月 20 日
編集済み: Arif 2024 年 2 月 21 日
hi @Stephen23 i try :
idx = strcmp(T.Joint,'5') & strcmp(T.OutputCase,'Pushover-x') & strcmp(T.OutputCase,'MODAL');
out = T(idx,{'StepNum','U1'})
but it was error... so it cant take two filters in one variable ?
Stephen23
Stephen23 2024 年 2 月 21 日
編集済み: Stephen23 2024 年 2 月 21 日
"but it was error"
Then you need to tell us exactly what the error is. Show us all of the red text.
"so it cant take two filters in one variable ?"
MATLAB does not limit how many AND operators can be chained one after another.
But your logic using AND is most likely incorrect: can you show one single value of the OUTPUTCASE field whose value is both equal to "Pushover-X" and also to "MODAL" ? That is what AND means.
I am guessing that you intended to use OR:
idx = strcmp(T.Joint,'5') & (strcmp(T.OutputCase,'Pushover-x') | strcmp(T.OutputCase,'MODAL'));
or perhaps ISMEMBER or MATCHES or similar:
idx = strcmp(T.Joint,'5') & ismember(T.OutputCase,{'Pushover-x','MODAL'});
Arif
Arif 2024 年 2 月 21 日
thanks stephen, ismember was the result

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

タグ

質問済み:

2024 年 2 月 19 日

コメント済み:

2024 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by