From: Matt Fig on
If it must be a for loop, use the same concept but with linear indexing.


A = magic(5)
for ii = 1:2:numel(A),A(ii) = 0;end
A
From: Kenneth on
jrenfree <jrenfree(a)gmail.com> wrote in message <4a625840-b75a-4047-a4b1-464588be97b3(a)v15g2000prn.googlegroups.com>...
> On Nov 17, 12:42?pm, "Kenneth " <cybeastfalza...(a)yahoo.com> wrote:
> > i know how to replace the elements using m(x,y)=0 where m is the matrix, and x and y are the row and column position of the element. What I want to know is how to replace every other element in the matrix with zero. preferably using a for loop.
>
> Why would you prefer a for loop? You can specify index intervals
> like:
>
> m(1:2:end, 1) = 0;
>
> That will make every other row of the 1st column equal to 0.


what i need is to flip this program so it does columns in rows(m(1,1:2:end,) = 0;
, also i need a for loop so it will work with any size matrix.
From: Loren Shure on
In article <hdv3h4$ffo$1(a)fred.mathworks.com>, cybeastfalzar99(a)yahoo.com
says...
> jrenfree <jrenfree(a)gmail.com> wrote in message <4a625840-b75a-4047-a4b1-464588be97b3(a)v15g2000prn.googlegroups.com>...
> > On Nov 17, 12:42?pm, "Kenneth " <cybeastfalza...(a)yahoo.com> wrote:
> > > i know how to replace the elements using m(x,y)=0 where m is the matrix, and x and y are the row and column position of the element. What I want to know is how to replace every other element in the matrix with zero. preferably using a for loop.
> >
> > Why would you prefer a for loop? You can specify index intervals
> > like:
> >
> > m(1:2:end, 1) = 0;
> >
> > That will make every other row of the 1st column equal to 0.
>
>
> what i need is to flip this program so it does columns in rows(m(1,1:2:end,) = 0;
> , also i need a for loop so it will work with any size matrix.
>

m = rand(100,10);
m(1:2:end) = 0;

--
Loren
http://blogs.mathworks.com/loren
From: Kenneth on
jrenfree <jrenfree(a)gmail.com> wrote in message <4a625840-b75a-4047-a4b1-464588be97b3(a)v15g2000prn.googlegroups.com>...
> On Nov 17, 12:42?pm, "Kenneth " <cybeastfalza...(a)yahoo.com> wrote:
> > i know how to replace the elements using m(x,y)=0 where m is the matrix, and x and y are the row and column position of the element. What I want to know is how to replace every other element in the matrix with zero. preferably using a for loop.
>
> Why would you prefer a for loop? You can specify index intervals
> like:
>
> m(1:2:end, 1) = 0;
>
> That will make every other row of the 1st column equal to 0.

I got it to work, but what i would like it to do now is alternate. so in the first row it will start at 1 and set every other one to zero, and in the second row it will start at 2 and set every other one. and so on, ect.
From: Kenneth on
"Kenneth " <cybeastfalzar99(a)yahoo.com> wrote in message <hdv4h2$i63$1(a)fred.mathworks.com>...
> jrenfree <jrenfree(a)gmail.com> wrote in message <4a625840-b75a-4047-a4b1-464588be97b3(a)v15g2000prn.googlegroups.com>...
> > On Nov 17, 12:42?pm, "Kenneth " <cybeastfalza...(a)yahoo.com> wrote:
> > > i know how to replace the elements using m(x,y)=0 where m is the matrix, and x and y are the row and column position of the element. What I want to know is how to replace every other element in the matrix with zero. preferably using a for loop.
> >
> > Why would you prefer a for loop? You can specify index intervals
> > like:
> >
> > m(1:2:end, 1) = 0;
> >
> > That will make every other row of the 1st column equal to 0.
>
> I got it to work, but what i would like it to do now is alternate. so in the first row it will start at 1 and set every other one to zero, and in the second row it will start at 2 and set every other one. and so on, ect. also, it needs to work for any matrix(even 1000x1000)