フィルターのクリア

Select specific data with conditions from struct ?

21 ビュー (過去 30 日間)
azdoud youssef
azdoud youssef 2018 年 1 月 19 日
コメント済み: azdoud youssef 2018 年 1 月 19 日
Hi, I have the following structure: data
I need to select those where data.name = t1 and data.value is between 0.5 and 0.8
Glad for any help
data(1:6) = struct('name', '', 'value', zeros(1,1));
data(1).name= 't1'; data(1).value=0.569;
data(2).name= 't2'; data(2).value=0.657;
data(3).name= 't1'; data(3).value=0.98;
data(4).name= 't6'; data(4).value=0.451;
data(5).name= 't2'; data(5).value=0.354;
data(6).name= 't1'; data(6).value=0.746;

採用された回答

Stephen23
Stephen23 2018 年 1 月 19 日
編集済み: Stephen23 2018 年 1 月 19 日
vec = [data.value];
idx = strcmp('t1',{data.name}) & vec>0.5 & vec<0.8;
out = data(idx);
giving:
>> out.name
ans = t1
ans = t1
>> out.value
ans = 0.56900
ans = 0.74600

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Statistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by