Fix dynamically named variables

2 ビュー (過去 30 日間)
Ryan Rose
Ryan Rose 2021 年 5 月 3 日
コメント済み: Ryan Rose 2021 年 5 月 4 日
I am working with data from another program that dynamically names table variables. This needs to be corrected to make my script work.
Currently Vartable.Properties.VariableNames=
{'VarA_f01_01/01/2021'} {'VarB_f01_01/01/2021'} {'VarC_f01_01/01/2021'}
I would like this to look like
{'VarA'} {'VarB'} {'VarC'}
Is there a way to do this for multiple variable names without a bunch of if contains statements?
The variable names are in a standardized format but the numbers dates and letters will change. Sometimes certain variables will not be present and only VarA and VarC may be in the table which further complicates things.
Any help is appriciated.
  2 件のコメント
Jeff Miller
Jeff Miller 2021 年 5 月 3 日
It's hard to tell from these examples what the full range of "before" and "after" variable might be. For the names shown, for example, it would be sufficient to rename each variable with the part of its original name preceding the first underscore. Would that always work?
Ryan Rose
Ryan Rose 2021 年 5 月 4 日
It should I just dont know how to do it for lots of variables.

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

採用された回答

Matt J
Matt J 2021 年 5 月 4 日
編集済み: Matt J 2021 年 5 月 4 日
Vartable.Properties.VariableNames=extractBefore( Vartable.Properties.VariableNames, '_');
  1 件のコメント
Ryan Rose
Ryan Rose 2021 年 5 月 4 日
Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by