필터 지우기
필터 지우기

Updating a Cell Array wit listbox and popupmenu options

조회 수: 2 (최근 30일)
B_Richardson
B_Richardson 2011년 6월 29일
Simple question: Given a cell array of: CellArray(1,50)={zeros(10,N)}
1. The 10 refers to 10 popupmenu options 2. The N refers to listboxoptions
So it's popupmenu options x listbox options
How can I input 1's for the currently selected listbox and popupmenu options? For instance:
popupmenu option #3 is selected; listbox options 4, 5, 7 are selected;
I want to produce this in my matrix based on those selections:
0 0 0 0 0 0 0 0 0 ..... N 0.......N 1 0 0 0 1 1 0 1 0 0 0 ....N 0.......N . . . . Please let me know if I'm not explaining this clearly!

채택된 답변

Matt Fig
Matt Fig 2011년 6월 29일
Is it that you have 10 popupmenus and N listboxes, or one popumenu and one listbox?
If you only have one of each, then shouldn't your array only have two ones in it?
Perhaps if you give a very small example...
%
%
%
EDIT In response to clarifying comments.
Here is an example, based on what you said. Note that the array is only displayed when a popup value is chosen, so select from the listbox first to fill in a column other than the first. You could alter this by putting the same code in the listbox callback...
function [] = pop_ex()
% Help goes here.
S.fh = figure('units','pixels',...
'position',[10 30 120 140],...
'menubar','none',...
'name','slider_ex',...
'numbertitle','off',...
'resize','off');
S.pp = uicontrol('style','pop',...
'unit','pix',...
'position',[20 20 120 40],...
'string',{'one','two','three','four'},...
'callback',@pp_call);
S.ls = uicontrol('style','list',...
'unit','pix',...
'position',[20 80 120 40],...
'string',{'lone','ltwo','lthree','lfour','lfive','lsix'});
guidata(S.fh,S)
function [] = pp_call(varargin)
% Callback for the popup.
S = guidata(gcbf);
A = zeros(length(get(S.pp,'string')),length(get(S.ls,'string')));
R = get(S.pp,'val');
C = get(S.ls,'val');
I = sub2ind(size(A),[R R],[1 C]);
A(I) = 1 % Display in command window.
%
%
%
%
EDIT Address multi-selectable listboxes.
If the listbox is multi-selctable, then use this line instead:
I = sub2ind(size(A),[R repmat(R,1,length(C))],[1 C]);
  댓글 수: 14
B_Richardson
B_Richardson 2011년 6월 30일
I'm not sure if I understand that. So are you saying to use the array "A" to fill my cell array, "C(1,50)" ?
So it would be:
C(:) = {A}?
B_Richardson
B_Richardson 2011년 6월 30일
So I came up with this:
R = get(handles.popupmenu1,'val');
C = get(handles.listbox1,'val');
A = zeros(length(get(handles.popupmenu1,'string')),length(get(handles.listbox1,'string')));
I = sub2ind(size(A),[R repmat(R,1,length(C))],[1 C]);
Z = cell(1,50);
A(I) = 1
for i = 1: 50
Z(:) = {A}
end
The only problem is that it saves all of the listbox options and all of the popupmenu options instead of just the currently selected items.
But it does store the array A into the 1 x 50 cell array Z so I guess its a start.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by