[scilab-Users] problem with creating loop
Francis Drossaert
Francis.Drossaert at pgs.com
Fri Aug 13 10:55:09 CEST 2010
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20100813/e7b08eca/attachment.htm>
More information about the users
mailing list