How do you insert the members of a structure from workspace into a list box
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Chris E.
2013년 7월 11일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!