f



Accessing GUI data in Matlab workspace

Hi,

I am a new user of GUIDE. I would like to construct a GUI, where
there are two list-boxes (or pop-up menus as I am not sure what the
difference between the two is). I will have a predefined list of
variables (say 10) in the first list box and 3 variables in the
second listbox.

For every instance of a variable that I select in the first list box,
I should be able to associate it with a variable from the second
listbox.

The result could be available in a cell array or similar in the
Matlab workspace.

Variable from List box 1 Variable from List box 2

Variable 1 Value 3
Variable 2 Value 1
Variable 3 Value 2
.... ...
.... ...
Variable 9 Value 3
Variable 10 Value 2
0
5/9/2005 2:57:57 PM
comp.soft-sys.matlab 211266 articles. 15 followers. lunamoonmoon (258) is leader. Post Follow

3 Replies
359 Views

Similar Articles

[PageSpeed] 56

Sachin schrieb:
> Hi,
>
> I am a new user of GUIDE. I would like to construct a GUI, where
> there are two list-boxes (or pop-up menus as I am not sure what the
> difference between the two is). I will have a predefined list of
> variables (say 10) in the first list box and 3 variables in the
> second listbox.
>
> For every instance of a variable that I select in the first list box,
> I should be able to associate it with a variable from the second
> listbox.
>
> The result could be available in a cell array or similar in the
> Matlab workspace.
>
> Variable from List box 1 Variable from List box 2
>
> Variable 1 Value 3
> Variable 2 Value 1
> Variable 3 Value 2
> ... ...
> ... ...
> Variable 9 Value 3
> Variable 10 Value 2

Hint

help assignin

string = 'Variable 1';
Value = 123.245;
assignin('base', string, Value);
%base = Matlab Workspace

greetz Slash

0
pba1h1di (25)
5/10/2005 5:59:14 AM
Hey, that was nice to know and it works fine. Though I have another
question for you. I had a function, the result of which I write to
the workspace now using 'assignin'.

However, I also have a few sub-functions within this main function,
to which I would like to pass on the values. Any more hidden
functions there which I dont know of yet??

Thanks a ton,
-Sachin
Slash wrote:
>
>
>
> Sachin schrieb:
>> Hi,
>>
>> I am a new user of GUIDE. I would like to construct a GUI,
where
>> there are two list-boxes (or pop-up menus as I am not sure what
> the
>> difference between the two is). I will have a predefined list
of
>> variables (say 10) in the first list box and 3 variables in the
>> second listbox.
>>
>> For every instance of a variable that I select in the first
list
> box,
>> I should be able to associate it with a variable from the
second
>> listbox.
>>
>> The result could be available in a cell array or similar in the
>> Matlab workspace.
>>
>> Variable from List box 1 Variable from List box 2
>>
>> Variable 1 Value 3
>> Variable 2 Value 1
>> Variable 3 Value 2
>> ... ...
>> ... ...
>> Variable 9 Value 3
>> Variable 10 Value 2
>
> Hint
>
> help assignin
>
> string = 'Variable 1';
> Value = 123.245;
> assignin('base', string, Value);
> %base = Matlab Workspace
>
> greetz Slash
>
>
0
5/11/2005 12:46:36 PM
Ok, here is my actual code...

When this code is run (say, select all three check boxes).

In the workspace, you will see three variables, Val_a, Val_b, Val_C
(all doubles) and ans (cell array).

I first need to vertically concatenate Val_a, Val_b and Val_c (which
is easy) and the resulting vector needs to be horizontally
concatenated to ans.

Any ideas??

Thanks,
-Sachin
%------------------------------------------------------
function [Result, Val_a, Val_b, Valc] = DialogSelection

% Create the figure, 5 inches by 3 inches, and set the default
% uicontrol background color to match the figure's color
F=figure('Units','inch',...
    'Position',[2.5 0.75 5 6.5],...
    'Menubar','none',...
    'NumberTitle','off',...
    'Toolbar','none',...
    'WindowStyle','modal',...
    'DefaultUicontrolBackgroundColor',get(0,'DefaultFigureColor'),...
    'Name','Trigger Selection');

% Create the three checkboxes from which the user will select
C1=uicontrol('Style','checkbox',...
    'Units','inch',...
    'Position',[1 5.5 3 0.75],...
    'String','E_DGPL_A',...
    'Tag','FirstBox');

Ca=uicontrol('Style','popup',...
    'Units','inch',...
    'Position',[2 5.25 2 0.75],...
    'String','|High|Low|High2Low|Low2High',...
    'Tag','FirstBox');

C2=uicontrol('Style','checkbox',...
    'Units','inch',...
    'Position',[1 5 3 0.75],...
    'String','E_DGPL_B',...
    'Tag','SecondBox');

Cb=uicontrol('Style','popup',...
    'Units','inch',...
    'Position',[2 4.75 2 0.75],...
    'String','|High|Low|High2Low|Low2High',...
    'Tag','FirstBox');

C3=uicontrol('Style','checkbox',...
    'Units','inch',...
    'Position',[1 4.5 3 0.75],...
    'String','U_DGPL_A',...
    'Tag','ThirdBox');

Cc=uicontrol('Style','popup',...
    'Units','inch',...
    'Position',[2 4.25 2 0.75],...
    'String','|High|Low|High2Low|Low2High',...
    'Tag','FirstBox');

% Create the OK button to specify when to poll the checkboxes
OK=uicontrol('Style','pushbutton',...
    'Units','inch',...
    'Position',[1 0.05 3 0.4],...
    'Tag','OK',...
    'String','OK',...
    'Callback',@PushedOK);

% Wait until OK button gets pressed or figure is closed
% Figure is modal as well
waitfor(F,'Userdata')

% We use FLIPUD because we created checkbox 3 last
Result=flipud(get(F,'Userdata'));

Val_a = get(Ca,'Value')
Val_b = get(Cb,'Value')
Val_c = get(Cc,'Value')

assignin('base','Val_a',Val_a)
assignin('base','Val_b',Val_b)
assignin('base','Val_c',Val_c)

% Close the dialog
close(F)

function [WhatWasSelected, Val_a, Val_b, Val_c] = PushedOK(varargin)

% Figure out which checkboxes were selected
SelectedBoxes=findobj(gcbf,'Style','checkbox','Value',1);

% Get their strings (as a cell array) and put it in the
% UserData of the dialog figure

set(gcbf,'Userdata',get(SelectedBoxes,'String'));
%------------------------------------------------------

Sachin wrote:
>
>
> Hey, that was nice to know and it works fine. Though I have another
> question for you. I had a function, the result of which I write to
> the workspace now using 'assignin'.
>
> However, I also have a few sub-functions within this main function,
> to which I would like to pass on the values. Any more hidden
> functions there which I dont know of yet??
>
> Thanks a ton,
> -Sachin
> Slash wrote:
>>
>>
>>
>> Sachin schrieb:
>>> Hi,
>>>
>>> I am a new user of GUIDE. I would like to construct a GUI,
> where
>>> there are two list-boxes (or pop-up menus as I am not sure
> what
>> the
>>> difference between the two is). I will have a predefined
list
> of
>>> variables (say 10) in the first list box and 3 variables in
> the
>>> second listbox.
>>>
>>> For every instance of a variable that I select in the first
> list
>> box,
>>> I should be able to associate it with a variable from the
> second
>>> listbox.
>>>
>>> The result could be available in a cell array or similar in
> the
>>> Matlab workspace.
>>>
>>> Variable from List box 1 Variable from List box 2
>>>
>>> Variable 1 Value 3
>>> Variable 2 Value 1
>>> Variable 3 Value 2
>>> ... ...
>>> ... ...
>>> Variable 9 Value 3
>>> Variable 10 Value 2
>>
>> Hint
>>
>> help assignin
>>
>> string = 'Variable 1';
>> Value = 123.245;
>> assignin('base', string, Value);
>> %base = Matlab Workspace
>>
>> greetz Slash
>>
>>
0
5/12/2005 7:38:13 PM
Reply: