saving structures in a database and retrieve the fields data
2 次查看(过去 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
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!