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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 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="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div lang="EN-GB" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Hi Marcin,</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;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:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">for it=1:3;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> average(it) =mean(a(a(:,1)==it,2:$)); </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">end</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;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:11.0pt;color:#1F497D">msk = a(:,1)==it; // creates a boolean
mask vector</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;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:11.0pt;color:#1F497D">average=mean(anew); // calculate the average of
the matrix</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Cheers</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Francis</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt">From:</span></b><span lang="EN-US" style="font-size:10.0pt"> 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:10.0pt">Hello,</span></span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">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:10.0pt">a
= [1 10 20</span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">
2 20 30</span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">
3 30 40</span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">
1 20 10</span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">
3 40 40<br clear="all">
2 20 10]</span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">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:10.0pt"> </span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">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>