필터 지우기
필터 지우기

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 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