<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<META content="MSHTML 6.00.2800.1649" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff size=2>Hi
Marcin,</FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff size=2>You
can find the unique elements of your first column using the unique function
like:</FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2>-->u=unique(xy_w(:,1))<BR> u =</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2> 1.<BR> 4.<BR>
6.<BR></FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff size=2>Then
you can iterate over those values using:</FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2>-->for x=u'<BR>-->av =
mean(xy_w(find(xy_w(:,1)==x),2:3),'r')<BR>-->end<BR> av
=</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2> 21. 21.<BR> av
=</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2> 44. 46.<BR> av
=</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2> 35. 35.<BR></FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff size=2>Hope
that helps.</FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2>Mike.</FONT></SPAN></DIV>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2> </DIV></FONT></SPAN>
<DIV><SPAN class=906203617-14082010><FONT face=Arial color=#0000ff
size=2> </DIV></FONT></SPAN>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> marcin.wozniczka Gazeta.pl
[mailto:marcin.wozniczka@gazeta.pl]<BR><B>Sent:</B> 14 August 2010
18:05<BR><B>To:</B> users@lists.scilab.org<BR><B>Subject:</B> Re:
[scilab-Users] problem with creating loop<BR><BR></FONT></DIV>Ok I understand,
but what can I do if the numbers in the first column are not 1, 2, 3 etc., for
example matrix a is looking like that:
<DIV>
<DIV>xy_w = [...</DIV>
<DIV>6 10 10</DIV>
<DIV>1 20 20</DIV>
<DIV>4 40 40</DIV>
<DIV>4 50 50</DIV>
<DIV>6 60 60</DIV>
<DIV>4 42 48</DIV>
<DIV>1 22 22 ];</DIV></DIV>
<DIV><BR></DIV>
<DIV>I modified your function for that:</DIV>
<DIV>
<DIV>nr = a(:,1); //This is wrong</DIV>
<DIV>for i=1:3 //This is wrong</DIV>
<DIV> ps = nr(i);</DIV>
<DIV> for j=1:3</DIV>
<DIV> av(i,j) =mean(a(a(:,1) == ps,j));</DIV>
<DIV> end</DIV>
<DIV>end</DIV>
<DIV><BR></DIV>
<DIV>but I have problem to define final value of 'i'. I know that it's
conecting with 'nr' so if you know how I can declare only once the numbers
from first column (only numbers: 6, 1 & 4)</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>
<DIV>
<DIV class=h5>
<P class=MsoNormal style="MARGIN: 0px">-- <BR>Marcin Wo¼niczka</P>
<DIV><BR></DIV>
<DIV><BR></DIV></DIV></DIV></DIV></DIV><BR>
<DIV class=gmail_quote>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV lang=EN-GB vlink="purple" link="blue">
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d">Hi
Marcin,</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d">There are
off course various ways to solve your problem. Probably the shortest way to
do is like this:</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d">for
it=1:3;</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"> average(it)
=mean(a(a(:,1)==it,2:$)); </SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d">end</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d">It loops
over the elements in the first column. The second line is a bit more cryptic
but can be split in separate line:</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d">msk =
a(:,1)==it;
// creates a boolean mask vector</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d">anew =
a(msk,2:$);
// creates a new matrix using the mask over the second to last columns of
a</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d">average=mean(anew);
// calculate the average of the matrix</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d">Cheers</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d">Francis</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d"></SPAN> </P>
<DIV
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
<P class=MsoNormal><B><SPAN lang=EN-US
style="FONT-SIZE: 10pt">From:</SPAN></B><SPAN lang=EN-US
style="FONT-SIZE: 10pt"> marcin.wozniczka Gazeta.pl [mailto:<A
href="mailto:marcin.wozniczka@gazeta.pl"
target=_blank>marcin.wozniczka@gazeta.pl</A>] <BR><B>Sent:</B> 12 August
2010 20:59<BR><B>To:</B> <A href="mailto:users@lists.scilab.org"
target=_blank>users@lists.scilab.org</A><BR><B>Subject:</B> [scilab-Users]
problem with creating loop</SPAN></P></DIV>
<DIV>
<DIV></DIV>
<DIV class=h5>
<P class=MsoNormal> </P>
<P class=MsoNormal><SPAN><SPAN
style="FONT-SIZE: 10pt">Hello,</SPAN></SPAN></P>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">I have small problem with
my program/function in Scilab. I want to loop function - the loop must be
repeated until all datas will be use. For example I have matrix
'a'</SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">a = [1 10
20</SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">
2 20 30</SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">
3 30 40</SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">
1 20 10</SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">
3 40 40<BR clear=all> 2 20 10]</SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">and I'm taking all lines
which have in the first column the same number, take average of this and put
to the other matrix. I created function which can do all this thing but I
don't have any idea how to make a reapeted loop from
this. </SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt"></SPAN> </P></DIV>
<DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt">Can you help
me?</SPAN></P></DIV>
<P class=MsoNormal><BR>-- <BR>Marcin Wo¼niczka</P></DIV></DIV></DIV><BR>This
e-mail, including any attachments and response string, may contain
proprietary information which is confidential and may be legally privileged.
It is for the intended recipient only. If you are not the intended recipient
or transmission error has misdirected this e-mail, please notify the author
by return e-mail and delete this message and any attachment immediately. If
you are not the intended recipient you must not use, disclose, distribute,
forward, copy, print or rely on this e-mail in any way except as permitted
by the author.
</DIV></BLOCKQUOTE></DIV><BR><BR
clear=all><BR>-- <BR>Pozdrawiam,<BR>Marcin
Wo¼niczka<BR></DIV></BLOCKQUOTE></BODY></HTML>