How to account for a change in variabale name when using "find"?

1 回表示 (過去 30 日間)
Tomaszzz
Tomaszzz 2022 年 5 月 17 日
コメント済み: Tomaszzz 2022 年 5 月 19 日
Hi all,
I have a large excell file in which I am intending to find a specific variables in this way:
idx_lfoot_start = find(strcmp(data_raw(:, 2), '"HX210.11.31.M9-LF S0060"'));
idx_lfoot_end = find(strcmp(data_raw(:, 2), '"HX210.11.31.M9-RF S0060"'));
However, the variables, depending on a file, can be named:
"HX210.11.31.M7-LF S0060"
"HX210.11.31.M7-RF S0060"
I am using this variable as an index to extract data, an example below. If I do not acccount for this variation in the name, nothing is identified. How could I account for this in the code?
% indices between idx_lfoot_start and idx_lfoot_end
idx = arrayfun(@(idxStart, idxEnd) idxStart:idxEnd, idx_lfoot_start, idx_lfoot_end,...
'UniformOutput', false);
% corresponding values for variables of interest
c.l_avgP = cellfun(@(idxx) data_raw(idxx(strcmp(data_raw(idxx, 1), ...
'Average Pressure (PSI)')), 2), idx);

採用された回答

Monica Roberts
Monica Roberts 2022 年 5 月 17 日
Sounds like a job for regexp. For example:
>> regexp("HX210.11.31.M7-LF S0060","HX210*-LF S0060")
ans =
1
>> regexp("HX210.11.31.M7-LF S0060","HX210*-RF S0060")
ans =
[]
  3 件のコメント
Monica Roberts
Monica Roberts 2022 年 5 月 17 日
Without seeing "data_raw" I'm not sure what the code should look like. What does this give you?
regexp(data_raw(:, 2),"HX210.*-LF S0060")
Tomaszzz
Tomaszzz 2022 年 5 月 19 日
Thanks, this does the trick

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by