Re: What's wrong with this small code?
- To: mathgroup at smc.vnet.net
- Subject: [mg50051] Re: [mg49928] What's wrong with this small code?
- From: Omega Consulting <info at omegaconsultinggroup.com>
- Date: Fri, 13 Aug 2004 05:55:47 -0400 (EDT)
- References: <200408060709.DAA21469@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Aug 6, 2004, at 2:09 AM, Justin wrote: > I made a 4*4 IdentityMatrix, named "test". Then, I wanna show the > diagnol "1" in RED. After running the following code, I got the red > diagnol opposite to the "1" diagnol. What's wrong with this code? Can > anybody find it out? > > Thanks. > > test = IdentityMatrix[4]; > {numRows, numColumns} = Dimensions[test]; > Show[ > Graphics[ > RasterArray[ > Table[ > If[ > test[[i, j]] > 0, > RGBColor[1, 0, 0], > RGBColor[0, 1, 0] > ], > {i, 1, numRows}, {j, 1, numColumns} > ] > ] > ] > ] Raster and RasterArray are upside-down compared to most raster formats. That is, the first row in the matrix is the bottom row. The row number is supposed to match the y-axis of the coordinate system (which is 0 at the bottom and increases upward). The following does what you want: test = Reverse[IdentityMatrix[4]]; {numRows, numColumns} = Dimensions[test]; Show[ Graphics[ RasterArray[ Table[ If[ test[[i, j]] > 0, RGBColor[1, 0, 0], RGBColor[0, 1, 0] ], {i, 1, numRows}, {j, 1, numColumns} ] ] ] ] ---------------------------------------------- Omega Consulting The final answer to your Mathematica needs. http://omegaconsultinggroup.com
- References:
- What's wrong with this small code?
- From: jianchaoyao@hotmail.com (Justin)
- What's wrong with this small code?