特定の文字が含まれる隣の値を抽出する

下記記載の行列Aにおいて、2列目の文字が引上げと書かれている左の値を抽出し行列Bのように出力したいです。色々な関数を使用してみたのですがうまくいきません。これを実現できるコードをご教授頂きたいです。
A=
8.17150500000000,'保持'
8.17150500000000 ,'保持'
8.17150500000000,'保持'
8.17150500000000 ,'保持'
7.90358600000000,'引上げ'
7.90358600000000 ,'引上げ'
7.85893300000000,'引上げ'
7.90358600000000,'引上げ'
B=
7.90358600000000
7.90358600000000
7.85893300000000
7.90358600000000

 Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 22 Jul. 2023

1 Stimme

ドキュメント「条件を満たす配列要素の検索」が参考になると思います。"引上げ"に合致する行をインデックスで取得すれば良いかと。
format long
A = readtable('data.csv', 'NumHeaderLines', 0, 'TextType', 'string')
A = 8×2 table
Var1 Var2 ________ _______ 8.171505 "保持" 8.171505 "保持" 8.171505 "保持" 8.171505 "保持" 7.903586 "引上げ" 7.903586 "引上げ" 7.858933 "引上げ" 7.903586 "引上げ"
idx = A.Var2 == "引上げ";
B = A.Var1(idx)
B = 4×1
7.903586000000000 7.903586000000000 7.858933000000000 7.903586000000000

Weitere Antworten (0)

Kategorien

Mehr zu データ型の識別 finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2022a

Community Treasure Hunt

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

Start Hunting!