From: Arjun Kishore on
Need help ..
i have a matrix filled with 0 to 3 in random... the number of zero's 1's 2's and 3's changes in every iteration... i need to plot number of 0's 1's 2's and 3's in a graph and update it dynamically in a same plot for each iteration..


ca1=randint(10,10,[1,4]);% Value initialization

for k=1:1:iteration
for i = 1:1:10
for j= 1:1:10
if ca1(i,j)==0
zero= zero+1;
end;
if ca1(i,j)==1
one=one+1;
end;
if ca1(i,j)==2
two=two+1;
end
if ca1(i,j)==3
three=three+1;
end
end;
end;
how to plot graph of all number of 0's.1's,2's,3's and update it dynamically as loop executes..??
From: us on
"Arjun Kishore " <arjunitp(a)gmail.com> wrote in message <htqcu2$h62$1(a)fred.mathworks.com>...
> Need help ..
> i have a matrix filled with 0 to 3 in random... the number of zero's 1's 2's and 3's changes in every iteration... i need to plot number of 0's 1's 2's and 3's in a graph and update it dynamically in a same plot for each iteration..
>
>
> ca1=randint(10,10,[1,4]);% Value initialization
>
> for k=1:1:iteration
> for i = 1:1:10
> for j= 1:1:10
> if ca1(i,j)==0
> zero= zero+1;
> end;
> if ca1(i,j)==1
> one=one+1;
> end;
> if ca1(i,j)==2
> two=two+1;
> end
> if ca1(i,j)==3
> three=three+1;
> end
> end;
> end;
> how to plot graph of all number of 0's.1's,2's,3's and update it dynamically as loop executes..??

one of the many solutions is outlined below
- copy/paste into your command window or an M-file...

% the data
v=ceil(4*rand(10));
% the engine
nc=histc(v(:),1:4);
nv=numel(v);
x=1:4;
y=zeros(size(x));
ah=axes(...
'xlim',[0,max(x)+1],...
'ylim',[0,1.1*max(nc)],...
'xtick',x);
lh=line([x;x],[y;y],...
'linewidth',5,...
'color',[0,0,0]);
shg;
for i=1:nv
cn=v(i);
y(cn)=y(cn)+1;
set(lh(cn),'ydata',[0;y(cn)]);
pause(.025);
end

us
From: Arjun Kishore on
"us " <us(a)neurol.unizh.ch> wrote in message <htqk73$p3l$1(a)fred.mathworks.com>...
> "Arjun Kishore " <arjunitp(a)gmail.com> wrote in message <htqcu2$h62$1(a)fred.mathworks.com>...
> > Need help ..
> > i have a matrix filled with 0 to 3 in random... the number of zero's 1's 2's and 3's changes in every iteration... i need to plot number of 0's 1's 2's and 3's in a graph and update it dynamically in a same plot for each iteration..
> >
> >
> > ca1=randint(10,10,[1,4]);% Value initialization
> >
> > for k=1:1:iteration
> > for i = 1:1:10
> > for j= 1:1:10
> > if ca1(i,j)==0
> > zero= zero+1;
> > end;
> > if ca1(i,j)==1
> > one=one+1;
> > end;
> > if ca1(i,j)==2
> > two=two+1;
> > end
> > if ca1(i,j)==3
> > three=three+1;
> > end
> > end;
> > end;
> > how to plot graph of all number of 0's.1's,2's,3's and update it dynamically as loop executes..??
>
> one of the many solutions is outlined below
> - copy/paste into your command window or an M-file...
>
> % the data
> v=ceil(4*rand(10));
> % the engine
> nc=histc(v(:),1:4);
> nv=numel(v);
> x=1:4;
> y=zeros(size(x));
> ah=axes(...
> 'xlim',[0,max(x)+1],...
> 'ylim',[0,1.1*max(nc)],...
> 'xtick',x);
> lh=line([x;x],[y;y],...
> 'linewidth',5,...
> 'color',[0,0,0]);
> shg;
> for i=1:nv
> cn=v(i);
> y(cn)=y(cn)+1;
> set(lh(cn),'ydata',[0;y(cn)]);
> pause(.025);
> end
>

Thanks for your reply, but this not i want.. i need
numbers in y axis, iteretions in x axis and line graph of number of zeros ones twos and threes..the graph shud evolve as iteration increases...