create selecting menu

1 Ansicht (letzte 30 Tage)
DMGM Mazzoleni
DMGM Mazzoleni am 23 Mär. 2011
hy everybody, I have a simple question I have a (n x m) matrix and I want to create a menu where I can see all the "n" lines name and I can reorder them as I want by a simple clic-selection. I hope you understand my problem!!

Antworten (2)

Matt Fig
Matt Fig am 23 Mär. 2011
Will this work for your purposes? Simply call the file with a pre-existing 2D array.
function [] = selctrowsgui(A)
% Allows the user to select various rows of the input matrix, in any order
% and the create a new matrix made by taking the selected rows.
% Turning off the Multi-select checkbox will remove a row number once it
% has been chosen. Once the rows have been chosen, pressing the pushbutton
% will create the new matrix in the base.
S.fh = figure('units','pixels',...
'position',[40 40 140 940],...
'menubar','none',...
'name','Select Rows to reorder.',...
'resize','off',...
'numbertitle','off',...
'name','Row reorder');
S.STR = cell(size(A,1),1);
for ii = 1:size(A,1)
S.STR{ii} = sprintf('%s%i','Row Number: ',ii);
end
S.ls = uicontrol('style','list',...
'units','pix',...
'position',[10 60 120 830],...
'backgroundcolor','w',...
'string',S.STR,...
'HorizontalAlign','left',...
'callback',{@ls_call});
S.pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 120 40],...
'string','Create New',...
'fontsize',12,'fontweight','bold',...
'callback',{@pb_call});
S.ch = uicontrol('style','check',...
'units','pix',...
'position',[10 900 120 30],...
'string','Multi-select',...
'fontsize',12,'fontweight','bold',...
'value',1);
S.CNT = 0;
function [] = ls_call(varargin)
S.CNT = S.CNT + 1;
V = get(S.ls,'value');
C = S.STR(V);
I = findstr(C{1},' ');
C = str2double(C{1}(I(2):end));
S.SEL(S.CNT) = C;
if ~get(S.ch,'value')
S.STR(V) = [];
set(S.ls,'string',S.STR,'value',max(V-1,1))
end
end
function [] = pb_call(varargin)
% This will create a new matrix, A_matrix, in the base workspace.
assignin('base','A_matrix', A(S.SEL,:))
end
end

DMGM Mazzoleni
DMGM Mazzoleni am 24 Mär. 2011
thanks! I'll look up this morning but I think you've solved my problem ;)

Kategorien

Mehr zu Multidimensional Arrays 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!

Translated by