From: jens on
Hello everybody

I have the matlab code under.My idea is to use the go111 function to update the listbox by using the set function, but it does not seems to work?It is also not enough to change the string in the listbox, but also in some how the choices should fit. Anybody that can come up with an example how to update the contents of the listbox and correct the choices at the same time.


function Test()
close all

f=figure('name','Testing Data',...
'numbertitle','off',...
'menubar','none',...
'color',[0.85, 0.85, 0.85],...
'units','normalized',...
'position',[0 0.1 0.95 0.87]);

col=get(f,'color');

stringcell={'M1_Beer_Carlsberg';'M2_Book_Football';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M5_Book_Basketball';'M6_Beer_Slots'};



Beer = uicontrol('Style','radiobutton',...
'units','normalized',...
'position',[0.30 0.6 0.05 0.05],...
'backgroundcolor',col,...
'String','Beer',...
'callback',@go11,...
'Value',0);

function go11(varargin)
stringcell={'M1_Beer_Carlsberg';'M2_Book_Football';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M5_Book_Basketball';'M6_Beer_Slots'};
containsBook = cellfun(@(c) any(strfind(c, 'Book')), stringcell);
noBook = stringcell(~containsBook);
end



Book = uicontrol('Style','radiobutton',...
'units','normalized',...
'position',[0.30 0.65 0.05 0.05],...
'backgroundcolor',col,...
'String','Book',...
'callback',@go112,...
'Value',0);

function go112(varargin)
stringcell={'M1_Beer_Carlsberg';'M2_Book_Football';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M5_Book_Basketball';'M6_Beer_Slots'};
containsBeer = cellfun(@(c) any(strfind(c, 'Beer')), stringcell);
noBeer = stringcell(~containsBeer);
end




hlb=uicontrol('style','listbox',...
'units','normalized',...
'position',[0.10 0.6 0.15 0.1],...
'string',stringcell);

function go1(varargin)

choice=get(hlb,'value');
if choice==1
figure(2)
x=[1:10]
plot(x,x.^2)
elseif choice==2
figure(2)
x=[1:10]
plot(x,x.^3)
elseif choice==3
figure(2)
x=[1:10]
plot(x,x.^4)
elseif choice==4
figure(2)
x=[1:10]
plot(x,x.^5)
elseif choice==5
strings=get(hlb,'string');
strings(1)
end
end



uicontrol('style','pushbutton',...
'units','normalized',...
'position',[0.125 0.5 0.10 0.04],...
'string','Plot ',...
'backgroundcolor',col,...
'callback',@go1);



uicontrol('style','pushbutton',...
'units','normalized',...
'position',[0.125 0.3 0.10 0.04],...
'string','Plot2 ',...
'backgroundcolor',col,...
'callback',@go111);


function go111(varargin)
Books=get(Book,'Value')
Beers=get(Beer,'Value')

if Books~=0
% {}=set(hlb,'string')
noBeer=set(hlb,'string')
figure(6)
elseif Beers~=0
figure(7)
noBook=set(hlb,'string')

end
end
end




Best Regards

Jens
From: Cokelid on
On Feb 15, 11:19 am, "jens " <storebongho...(a)hotmail.com> wrote:
> I have the matlab code under.My idea is to use the go111 function to update the listbox by using the set function, but it does not seems to work?It is also not enough to change the string in the listbox, but also in some how the choices should fit. Anybody that can come up with an example how to update the contents of the listbox and correct the choices at the same time.

Hey Jens,

Your code is a little confusing (to say the least), it's very hard to
work out what you're trying to achieve! For starters what is "c"
supposed to represent in your go11 and go112 functions?

However to try and answer your question about your go111 function, you
have to call the set() function with the value you want to set, e.g.
set(hlb,'string',stringcell). Again it's not clear what you're trying
to do.

If you can come up with a simpler (i.e. the simplest possible) example
it'll be easier to help?

Justin

From: jens on
Cokelid <cokelid(a)googlemail.com> wrote in message <578eb664-6bd5-48e9-b395-29752e4fbce8(a)b18g2000vba.googlegroups.com>...
> On Feb 15, 11:19 am, "jens " <storebongho...(a)hotmail.com> wrote:
> > I have the matlab code under.My idea is to use the go111 function to update the listbox by using the set function, but it does not seems to work?It is also not enough to change the string in the listbox, but also in some how the choices should fit. Anybody that can come up with an example how to update the contents of the listbox and correct the choices at the same time.
>
> Hey Jens,
>
> Your code is a little confusing (to say the least), it's very hard to
> work out what you're trying to achieve! For starters what is "c"
> supposed to represent in your go11 and go112 functions?
>
> However to try and answer your question about your go111 function, you
> have to call the set() function with the value you want to set, e.g.
> set(hlb,'string',stringcell). Again it's not clear what you're trying
> to do.
>
> If you can come up with a simpler (i.e. the simplest possible) example
> it'll be easier to help?
>
> Justin

Thank you very much Justin for taking time to help me.
C is the handle to the cellfun. I know the example I showed is a bit confussing.
What I want is to use the radiobuttons in some way to only shows some specific strings in the listbox. When I press the Book radiobutton only the strings containing the word Book is shown in the listbox. I tried the example you surgested with the set command at it all worked fine. I definded two global variables noBook and noBeer that are cellarrays with strings containing respectively words with Beer and Book in the string.

I want when I press the pushbutton the go1111 is run and the strings in the cellarrays are updated/changed. My only problem now is to connect the strings to the different choices in the listbox. 'M2_Book_Football' and 'M5_Book_Basketball' should show choices 2 and 5 in the list box, but shows 1 and 2 now with the code under.

The global values are definded from the start in the GUI.

global noBook
global noBeer

noBook = []; % Initialize
noBeer = []; % Initialize

uicontrol('style','pushbutton',...
'units','normalized',...
'position',[0.125 0.3 0.10 0.04],...
'string','Plot2 ',...
'backgroundcolor',col,...
'callback',@go111);


function go111(varargin)

Beers=get(Beer,'Value');
Books=get(Book,'Value');
if Books~=0
set(hlb,'string',noBeer)
elseif Beers~=0
set(hlb,'string',noBook)

end
end

Best Regards

Jens
From: Cokelid on
On Feb 15, 2:22 pm, "jens " <storebongho...(a)hotmail.com> wrote:

> Thank you very much Justin for taking time to help me.
>  C is the handle to the cellfun. I know the example I showed is a bit confussing.
> What I want is to use the radiobuttons in some way to only shows some specific strings in the listbox. When I press the Book radiobutton only the strings containing the word Book is shown in the listbox. I tried the example you surgested with the set command at it all worked fine. I definded two global variables noBook and noBeer that are cellarrays with strings containing respectively words with Beer and Book in the string.
>
> I want when I press the pushbutton the go1111 is run and the strings in the cellarrays are updated/changed. My only problem now is to connect the strings to the different choices in the listbox. 'M2_Book_Football' and 'M5_Book_Basketball' should show choices 2 and 5 in the list box, but shows 1 and 2 now with the code under.

Sorry Jens, your code is crazy complicated & confusing, doesn't run
for me in any case. I can only suggest starting from scratch with a
much simpler example (and decent function names!).
From: jens on
Cokelid <cokelid(a)googlemail.com> wrote in message <49662096-6867-4369-8a16-3f371d1a5275(a)h2g2000yqj.googlegroups.com>...
> On Feb 15, 2:22 pm, "jens " <storebongho...(a)hotmail.com> wrote:
>
> > Thank you very much Justin for taking time to help me.
> >  C is the handle to the cellfun. I know the example I showed is a bit confussing.
> > What I want is to use the radiobuttons in some way to only shows some specific strings in the listbox. When I press the Book radiobutton only the strings containing the word Book is shown in the listbox. I tried the example you surgested with the set command at it all worked fine. I definded two global variables noBook and noBeer that are cellarrays with strings containing respectively words with Beer and Book in the string.
> >
> > I want when I press the pushbutton the go1111 is run and the strings in the cellarrays are updated/changed. My only problem now is to connect the strings to the different choices in the listbox. 'M2_Book_Football' and 'M5_Book_Basketball' should show choices 2 and 5 in the list box, but shows 1 and 2 now with the code under.
>
> Sorry Jens, your code is crazy complicated & confusing, doesn't run
> for me in any case. I can only suggest starting from scratch with a
> much simpler example (and decent function names!).

Dear Cokelid

Thanks again for your great effort in trying to help me.I really appreciatie it. I cannot get it to work the way I want with the code you surgested. Therefore I try on more time to describe in steps what I do with the GUI code under:

1)I press the radiobutton called Beer

2) I press the pushbutton called Plot2 andthe listbox shows the strings with the name Beer in it:

stringcell={'M1_Beer_Carlsberg';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M6_Beer_Slots'};

3)I choose from the listbox to plot M3_Beer_Heineken by clicking another pushbutton called Plot and a curve is shown in a new figure window. Instead of plotting x.^4 it plot x.^3. because it takes choice 2 instead of choice 3.
The same problem is if I try to plot 'M4_Beer_Newcastle'' it plots x.^4 instead of x.^5 because it takes choice 3 instead of choice 4.

Hope my explanation is better this time.

Best Regards

Jens



function Test()
close all
global noBook
global noBeer

noBook = []; % Initialize
noBeer = []; % Initialize

f=figure('name','Testing Data',...
'numbertitle','off',...
'menubar','none',...
'color',[0.85, 0.85, 0.85],...
'units','normalized',...
'position',[0 0.1 0.95 0.87]);

col=get(f,'color');

stringcell={'M1_Beer_Carlsberg';'M2_Book_Football';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M5_Book_Basketball';'M6_Beer_Slots'};



Beer = uicontrol('Style','radiobutton',...
'units','normalized',...
'position',[0.30 0.6 0.05 0.05],...
'backgroundcolor',col,...
'String','Beer',...
'callback',@go11,...
'Value',0);

function go11(varargin)
stringcell={'M1_Beer_Carlsberg';'M2_Book_Football';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M5_Book_Basketball';'M6_Beer_Slots'};
containsBook = cellfun(@(c) any(strfind(c, 'Book')), stringcell);
noBook = stringcell(~containsBook);
end



Book = uicontrol('Style','radiobutton',...
'units','normalized',...
'position',[0.30 0.65 0.05 0.05],...
'backgroundcolor',col,...
'String','Book',...
'callback',@go112,...
'Value',0);

function go112(varargin)
stringcell={'M1_Beer_Carlsberg';'M2_Book_Football';'M3_Beer_Heineken';'M4_Beer_Newcastle';'M5_Book_Basketball';'M6_Beer_Slots'};
containsBeer = cellfun(@(c) any(strfind(c, 'Beer')), stringcell);
noBeer = stringcell(~containsBeer);
end




hlb=uicontrol('style','listbox',...
'units','normalized',...
'position',[0.10 0.6 0.15 0.1],...
'string',stringcell);

function go1(varargin)

choice=get(hlb,'value');
if choice==1
figure(2)
x=[1:10]
plot(x,x.^2)
elseif choice==2
figure(2)
x=[1:10]
plot(x,x.^3)
elseif choice==3
figure(2)
x=[1:10]
plot(x,x.^4)
elseif choice==4
figure(2)
x=[1:10]
plot(x,x.^5)
elseif choice==5
figure(2)
x=[1:10]
plot(x,x.^6)
elseif choice==6
figure(2)
x=[1:10]
plot(x,x.^7)
end
end



uicontrol('style','pushbutton',...
'units','normalized',...
'position',[0.125 0.5 0.10 0.04],...
'string','Plot ',...
'backgroundcolor',col,...
'callback',@go1);



uicontrol('style','pushbutton',...
'units','normalized',...
'position',[0.125 0.3 0.10 0.04],...
'string','Plot2 ',...
'backgroundcolor',col,...
'callback',@go111);


function go111(varargin)

%origC = get(hlb, 'String')
%origValue = get(hlb, 'Value')
Beers=get(Beer,'Value')
Books=get(Book,'Value')
noBook
if Books~=0
set(hlb,'string',noBeer)




elseif Beers~=0

end

end

end