saving structures in a database and retrieve the fields data

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by