From: Edgar on 4 May 2010 09:59 Thank you both for your replies. I tried both soulutions a=[1 2 1 2]; bgcols = [.5, 0, 0;1,1,0]; arrayfun(@(idx) set(handles.t(idx),'BackgroundColor', bgcols(a(idx),:)),1:length(handles.t)); a=[1 2 1 2]; %1 or 2 for i=1:4 if a(i)==1 set(handles.t(i),'BackgroundColor',[.5,0,0]) elseif a(i)==2 set(handles.t(i),'BackgroundColor',[1,1,0]) end end But i still get the same message. ??? Reference to non-existent field 't'. Any Ideas? Thanks
From: Edgar on 4 May 2010 10:08
Walter Thank you for your help. it worked great Walter Roberson <roberson(a)hushmail.com> wrote in message <hrni9p$g2h$1(a)canopus.cc.umanitoba.ca>... > 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)); > > |