Re: problem with Part function
- To: mathgroup at smc.vnet.net
- Subject: [mg18186] Re: problem with Part function
- From: "Michael J Hirsch" <M_HIRSCH at prodigy.net>
- Date: Mon, 21 Jun 1999 22:50:31 -0400
- Organization: Prodigy Internet http://www.prodigy.com
- References: <7kho9q$qop@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Casubolo Dario wrote in message <7kho9q$qop at smc.vnet.net>... > >Just a little problem: >I've a matrix of zeros, say: >mat=Table[Table[0,{5}],{5}]; >then, I've a point in xy axys, >xy={3,3}; >now, I want the position {3,3} of matrix becomes 1; >if I write >mat[[xy]]=1; or mat[[{3,3}]]=1; it doesn't work; only mat[[3,3]]=1 >works, but I don't want rewrite all. >I think I've to use something like Map, Thread, Apply or so, but I don't >know what and how exactely; >please, someone help me. >THANK YOU > >Dario Casubolo >email: bubbola at workline.it > > > Dario: Accessing a specific part of a matrix can be done in a number of very similar ways: If you only are accessing one entry, you can do it in the following way: mat[[row_#,col_#]] = alpha, where alpha is whatever you want to put in the matrix. If you have more than one row, but only one column, you can do it in the following way: mat[[{row_list},col_#]] = alpha, where alpha is an appropriately sized matrix. And there are similar ways if you have more than one column. For your specific example, you want mat[[ xy[[1]] , xy[[2]] ]] = 1 I hope this helps! Michael J. Hirsch AMPAC, Inc. m_hirsch at prodigy.net