[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: S: Example

From: Ted Harding
Subject: Re: S: Example
Date: Tue, 18 Jul 1995 19:01:38 +0200 (BST)

( Re Message From: Nils Naumann )
> sorry, if this is a to stupid question. But I have red the manual and
> played around a long time and I can't find a solution, except two for
> loops, which will be really slow. 
> Doe's anyone have an example for changing elements of a matrix which
> match a special condition? I will change all members of a matrix which are 
> lower than the value x to the value y.
> The manual wrote I should use a matrix returned by the comparison operator, 
> but
> I can't figured out how I should pass this matrix to my expression.

Hi Nils,
Let X be the matrix to change, and c a comparison constant.
Let U be a matrix such that you want to change
X(i,j) to U(i,j) if X(i,j) < c, otherwise X(i,j) is unchanged.

C = (X < c);
Y = (1-C).*X + C.*U;

You can also do

Y(C) = U(C);

provided you have set do_fortran_indexing="true", but the first method
always works (or should).

If you have trouble with this, get back to me.

best wishes,
Ted.                                    (address@hidden)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]