help-octave
[Top][All Lists]
Advanced

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

Re: need some help with vectorization


From: Jaroslav Hajek
Subject: Re: need some help with vectorization
Date: Tue, 25 May 2010 09:50:53 +0200

2010/5/25 Miĥail Vasiljev <address@hidden>:
> Hello!
>
> One more question. I use fsolve to solve the system of nonlinear
> equations. To do this I need to form a vector y of equations, just as
> described in Octave manual. The problem is, to form the vector I need
> to take some data from the M by N matrix, there M*N == number of
> equations. In particular, I need to take the middle of the matrix,
> i.e. all the elements, except for that from the first and the last
> column and the first and the last row. Is there any way to do so in a
> vectorised way? For example, I need to do something like this:
>
> M = [ 1, 2, 3, 4;
>      5, 6, 7, 8;
>      9, 1, 2, 3;
>      4, 5, 6, 7]
>
> The part of the matrix I need is [6,7;1,2] here.
>
> y(1:16) = 1; #make's no sense, just for example
>
> So, here I need a vectored way to do something like:
>
> y(6) = M(2, 2)
> y(7) = M(2, 3)
> y(10) = M(3, 2)
> y(11) = M(3, 3)
>

I'm not sure I understand you, but the code above can be written like this:

y = ones (4);
y(2:3, 2:3) = M(2:3, 2:3);
y = y(:).';

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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