Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'ReplacePart inside While function' topicStudent Support Forum > General > "ReplacePart inside While function"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
03/27/12 2:23pm

From the documentation:
ReplacePart[expr,i->new]
yields an expression in which the ith part of expr is replaced by new.

Note that does not say
ReplacePart[expr,i->new]
stores the result of an expression in which the ith part of expr is replaced by new back into the variable expr.

Try storing the result, which is what I think you want.
n=3;
mat=ConstantArray[0,n];
j=0; While[j<n, mat=ReplacePart[mat,j+1->j+1]; j++];

URL: ,

Subject (listing for 'ReplacePart inside While function')
Author Date Posted
ReplacePart inside While function Alejandro 03/27/12 09:22am
Re: ReplacePart inside While function Bill Simpson 03/27/12 2:23pm
Re: Re: ReplacePart inside While function Alejandro 03/28/12 01:29am
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic