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 Nasser M. Abbasi 06/29/12 07:29am ========================== First, I have a multi-dimensional array (let's call it "array1") and I don't know a priori how many dimensions it has. ========================== Use Dimensions[] to find the size ======================== Second, I have an address of some element of array1 and it looks like: address1={2,2,1,5,3,1}; ======================== These are called positions, or indices, not address. There are no pointers in Mathematica. ======================= I know that I can extract this element using such code: (array1[[##]] & @@@ {address1})[[1]] ======================= I do not understand this code. To read element at position pos from array A, simply type A[[pos]] ============================ It will work just like "array1[[2,2,1,5,3,1]]". But the next line is not going to work: (array1[[##]] & @@@ {address1})[[1]] = 15; ============================ To assign a value to a list at position pos type A[[pos]=value =================================== That is my question. How to change the value of an element of array1 which can be found using address1? ===================================== Use [[ ]] Or Part. If given position in pos, something like Map[Part[A, Sequence @@ #] &, pos] see my note on basic examples using Mathematica arrays here http://12000.org/my_notes/mma_matlab_control/KERNEL/node66.htm 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