Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Writing to array using variable with address' topicStudent Support Forum > General > "Writing to array using variable with address"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Michael
07/02/12 00:43am

See if this does the things you want do:

In[1]:= address1 = {2, 2, 1, 5, 3, 1};

In[2]:= array1 = RandomReal[10, {2, 3, 4, 5, 4, 3}]; (* test case for array1; note the elements are all Real *)

In[3]:= array1 = ReplacePart[array1, address1 -> -2]; (* replace element at address by the Integer -2; store result back in array1 *)

In[4]:= Position[array1, _Integer] (* finds all Integers in array1 *)

Out[4]= {{2, 2, 1, 5, 3, 1}}

In[5]:= Extract[array1, address1] (* You can use Extract instead of array1[[##]]&... *)

Out[5]= -2



URL: ,

Subject (listing for 'Writing to array using variable with address')
Author Date Posted
Writing to array using variable with address Leon 06/28/12 04:52am
Re: Writing to array using variable with address Nasser M. Ab... 06/29/12 07:29am
Re: Re: Writing to array using variable with ad... Leon 06/29/12 09:48am
Re: Re: Re: Writing to array using variable wit... Nasser M. Ab... 06/29/12 1:07pm
Re: Writing to array using variable with address Michael 07/02/12 00:43am
Re: Re: Writing to array using variable with ad... Leon 07/02/12 10:56am
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic