How do you insert the members of a structure from workspace into a list box
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Chris E.
am 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!