[scilab-Users] problem with creating loop

marcin.wozniczka Gazeta.pl marcin.wozniczka at gazeta.pl
Sat Aug 14 19:05:19 CEST 2010


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:
xy_w = [...
6 10 10
1 20 20
4 40 40
4 50 50
6 60 60
4 42 48
1 22 22 ];

I modified your function for that:
nr = a(:,1);      //This is wrong
for i=1:3        //This is wrong
  ps = nr(i);
  for j=1:3
    av(i,j) =mean(a(a(:,1) == ps,j));
  end
end

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)

-- 
Marcin Woźniczka



Hi Marcin,
>
>
>
> There are off course various ways to solve your problem. Probably the
> shortest way to do is like this:
>
>
>
> for it=1:3;
>
>    average(it) =mean(a(a(:,1)==it,2:$));
>
> end
>
>
>
> It loops over the elements in the first column. The second line is a bit
> more cryptic but can be split in separate line:
>
> msk = a(:,1)==it;                                // creates a boolean mask
> vector
>
> anew = a(msk,2:$);                          // creates a new matrix using
> the mask over the second to last columns of a
>
> average=mean(anew);                  // calculate the average of the matrix
>
>
>
> Cheers
>
>
>
> Francis
>
>
>
>
>
>
>
>
>
> *From:* marcin.wozniczka Gazeta.pl [mailto:marcin.wozniczka at gazeta.pl]
> *Sent:* 12 August 2010 20:59
> *To:* users at lists.scilab.org
> *Subject:* [scilab-Users] problem with creating loop
>
>
>
> Hello,
>
> 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'
>
> a = [1 10 20
>
>        2 20 30
>
>        3 30 40
>
>        1 20 10
>
>        3 40 40
>        2 20 10]
>
> 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.
>
>
>
> Can you help me?
>
>
> --
> Marcin Woźniczka
>
> 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.   ­­
>



-- 
Pozdrawiam,
Marcin Woźniczka
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20100814/814c0dd1/attachment.htm>


More information about the users mailing list