Effacer les filtres
Effacer les filtres

Updating a Cell Array wit listbox and popupmenu options

2 vues (au cours des 30 derniers jours)
B_Richardson
B_Richardson le 29 Juin 2011
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!

Réponse acceptée

Matt Fig
Matt Fig le 29 Juin 2011
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 commentaires
B_Richardson
B_Richardson le 30 Juin 2011
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 le 30 Juin 2011
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by