フィルターのクリア

saving structures in a database and retrieve the fields data

1 回表示 (過去 30 日間)
genesis
genesis 2013 年 7 月 17 日
hi, i have a few structure eg
s(1).name = 'james';
s(1).num = 999;
s(2).name = 'hoper';
s(2).num = 111;
i want to save all of this this a database.
the next time i want to find the attributes, for example i find hoper in the database, i want the corresponding structure field .num to be displayed.
how can i do the above tasks? help..
thank you for your reply

回答 (1 件)

David Sanchez
David Sanchez 2013 年 7 月 17 日
I hope the following helps you:
var_found = 22; % variable found in database
%example struct
s.name='ww';
s.age=22;
n=fieldnames(s); % fieldnames within the struct
for k=1:numel(n)
if s.(n{k})==var_found
wanted_field = n{k}; % the field containing the value found in the database
break
end
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by