Updating a Cell Array wit listbox and popupmenu options
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!