From: Edgar on
Hello

I am trying to perform an iteration with several handles, however, i dont know if what i am trying to do is possible.
Basically a have a series of figure which tag name is t(i), where i is an integer from 1 to ten, now i am trying to change the background of this figures depending on a specific value. An example of what i am trying to do

for i=1:10
if a=1
set(handles.t(i),'BackgroundColor',[.5,0,0])
end
if a=2
set(handles.t(i),'BackgroundColor',[1,1,0])
end

however right now is clear that this code wont give me my expected solution.
Is there anyway i can do this?

In advance Thank you for yor help.
From: us on
"Edgar " <rolo46(a)hotmail.com> wrote in message <hrndma$8e$1(a)fred.mathworks.com>...
> Hello
>
> I am trying to perform an iteration with several handles, however, i dont know if what i am trying to do is possible.
> Basically a have a series of figure which tag name is t(i), where i is an integer from 1 to ten, now i am trying to change the background of this figures depending on a specific value. An example of what i am trying to do
>
> for i=1:10
> if a=1
> set(handles.t(i),'BackgroundColor',[.5,0,0])
> end
> if a=2
> set(handles.t(i),'BackgroundColor',[1,1,0])
> end
>
> however right now is clear that this code wont give me my expected solution.
> Is there anyway i can do this?
>
> In advance Thank you for yor help.

what is A(?)...

us
From: Edgar on


a=[1 2 1 2] %1 or 2

for i=1:4
if a(i)=1
set(handles.t(i),'BackgroundColor',[.5,0,0])
end
if a(i)=2
set(handles.t(i),'BackgroundColor',[1,1,0])
end
From: us on
"Edgar " <rolo46(a)hotmail.com> wrote in message <hrngg8$56l$1(a)fred.mathworks.com>...
>
>
> a=[1 2 1 2] %1 or 2
>
> for i=1:4
> if a(i)=1
> set(handles.t(i),'BackgroundColor',[.5,0,0])
> end
> if a(i)=2
> set(handles.t(i),'BackgroundColor',[1,1,0])
> end

% then, this

if a(i)=1

% must read

if a(i)==1

% given your simple loop, however, you should consider logical indexing...

us
From: Walter Roberson on
Edgar wrote:
>
>
> a=[1 2 1 2] %1 or 2
>
> for i=1:4
> if a(i)=1
> set(handles.t(i),'BackgroundColor',[.5,0,0])
> end if a(i)=2
> set(handles.t(i),'BackgroundColor',[1,1,0]) end

a single = is used for assignment. For comparison you would use two = beside
each other, as in

if a(i) == 1



But there really isn't any reason to go through that trouble. These two lines
together should be usable to replace the loop and if statements:


bgcols = [.5, 0, 0;1,1,0];
arrayfun(@(idx) set(handles.t(idx),'BackgroundColor', bgcols(a(idx),:)),
1:length(handles.t));