Effacer les filtres
Effacer les filtres

saving structures in a database and retrieve the fields data

1 vue (au cours des 30 derniers jours)
genesis
genesis le 17 Juil 2013
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

Réponses (1)

David Sanchez
David Sanchez le 17 Juil 2013
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

Community Treasure Hunt

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

Start Hunting!

Translated by