How do you insert the members of a structure from workspace into a list box

1 view (last 30 days)
Does anyone have an example of extracting members of a structure workspace so that they can be listed in a list box to be used later? Thanks for sharing your ideas.
tn

Accepted Answer

Chris E.
Chris E. on 11 Jul 2013
Hello Siew, Well if you want to extract information from a structure and put it into a list box, then it would look something like this:
%type guide and then make a list box press save. close out the guide and then paste the code below in the listbox1 callback function. then run the code and press the listbox1 on the gui. This should be able to run.
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
for x = 1:10 %makes fake structure data
s(x) = struct('field1',rand(1,5),'field2',rand(1,5),'field3',rand(1,5));
end
f1 = 'field1';
nums = reshape([s.(f1)]',5,10); %this extracts the fake structure data
s1 = nums(1,:);
s2 = nums(2,:);
s3 = nums(3,:);
tobedisplayed = num2str([s1; s2; s3])';
set(handles.listbox1,'string',tobedisplayed)%this displays it in the listbox1
I hope that helps!!!
Thanks,
Chris

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!