help-octave
[Top][All Lists]
Advanced

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

Re: Help needed on alternate row and column replacing matrix value


From: Przemek Klosowski
Subject: Re: Help needed on alternate row and column replacing matrix value
Date: Tue, 16 Dec 2014 10:13:50 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 12/15/2014 07:04 PM, seltek wrote:
I wish to create a matrix that would use the values of initial matrix (for
example a 3x3 ones matrix) to set the values in this new matrix (a 6x6
matrix (or 2*Nx2*N))to be equal to the values of the initial matrix on every
alternate column and row
Octave is very good at operations on entire matrices. You can of course write loops that go element-by-element but it's faster and easier to write 'vectorized' code---you just have to get used to it, and it's definitely worth the effort.

Octave has a range operator that can express your skipped index: 1:2:N, and so your assignment can be written as

new=initial(1:2:N,1:2:N)


reply via email to

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