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: Juan Pablo Carbajal
Subject: Re: Help needed on alternate row and column replacing matrix value
Date: Tue, 16 Dec 2014 10:25:49 +0100

On Tue, Dec 16, 2014 at 1:04 AM, seltek <address@hidden> 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
>
> For example:
>>The first row, first column value of the initial matrix would replace the
> first row,first column value of the new matrix
>>Then the first row, second column value of the initial matrix would replace
> the first row, third column value of the new matrix
>
> I tried making a do loop to do this but my loop would of course only work
> for the first column and first row; I would like this to be done for every
> odd row and column
>
> Here is the loop I used:
> N=3;
> A=ones(N,N);
> N_double=2*N;
> C=zeros(N_double,N_double);
> i=0;
> do
> i++;
> j=(2*i)-1;
> C(1,j)=A(i,1);
> C(j,1)=A(1,i);
> until(i==N);
> C
>
> I am quite new to using octave and any mathematical computing code so any
> help would be appreciated and i hope i havnt made this sound too confusing
> as i am struggling to explain this as it is
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/Help-needed-on-alternate-row-and-column-replacing-matrix-value-tp4667810.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave

Is this what you want?
A = ones (3,3);
B = zeros (6,6);
B(1:2:end,1:2:end) = A;



reply via email to

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