Double For-Loop: visual representa-tionFor[i=1, i<=IMax, i++,For[j=1, j<=JMax, j++,Task[i,j];];];A) Make ArrayPlot for single i,j valueIn[1]:=NX=10;(*Size of Table/2x2Array/Matrix*)i=1;(*row location*)j=2;(*column location*)V1=Array[1 &,(i-1) *NX+j] (*Vector of 1s up to current i,j location*)V2=Array[0 &, NX^2- ((i-1) *NX+j)](*Vector of 0s aftercurrent i,j location*)V12=Join[V1, V2]Length[V12] /NX^2Matrix12=Partition[V12, NX]Matrix12〚i〛〚j〛 =2;(*Set current location i,j to 2*)ArrayPlot[Matrix12, Mesh→True,ColorRules→ {1→Pink, 0→Yellow, 2→Gray}, ImageSize→200]Out[4]={1, 1}
In[11]:=(*Make list of all images and store in variable called ArrayPlotij*)ArrayPlotij=Reap[For[i=1, i≤NX, i++,For[j=1, j≤NX, j++,V1=Array[1 &,(i-1) *NX+j];(*Vector of 1s up to current i,j location*)V2=Array[0 &, NX^2- ((i-1) *NX+j)];(*Vector of 0s aftercurrent i,j location*)V12=Join[V1, V2];Matrix12=Partition[V12, NX];Matrix12〚i〛〚j〛 =2;(*Set current location i,j to 2*)Sow[ArrayPlot[Matrix12, Mesh→True, ColorRules→ {1→Pink, 0→Yellow,2→Gray}, ImageSize→200, PlotLabel→Style[StringJoin["{i,j} = {", ToString[i], ",", ToString[j], "}"], Black, 20]]];];];]〚2〛〚1〛;Length[ArrayPlotij]ArrayPlotij〚10〛Out[12]=100Out[13]={i,j} = {1,10}Now inspect Animate[ ] specifications:https://reference.wolfram.com/language/ref/Animate.htmlArrayPlot_DoubleLoop_TripleLoop.nb 3
In[23]:=Animate[ArrayPlotij〚Locij〛,{Locij, 1, NX^2, 1}, AnimationRunning→False]Out[23]=Locij{i,j,k} = {6,1,1}Method B: parameterize in terms of both i and j location - make the Array-Plot dynamically based upon a specific {i,j}ArrayPlot_DoubleLoop_TripleLoop.nb 5
In[19]:=Animate[ArrayPlot[Partition[Join[Array[1 &,(i-1) *NX+j-1],{2}, Array[0 &, NX^2- ((i-1) *NX+j)]], NX], Mesh→True,ColorRules→ {1→Pink, 0→Yellow, 2→Gray}, ImageSize→200, PlotLabel→Style[StringJoin["{i,j} = {", ToString[i], ",", ToString[j], "}"], Black, 20]],{i, 1, NX, 1},{j, 1, NX, 1}, AnimationRunning→False]Out[19]=ij{i,j} = {6,4}Method C: A mixture of A & B, in which we parameterize the plot in terms of a net Locij variable - then deduce {i,j} from LocijIn[16]:=(*Deduce{i,j}from Locij*)Locij=10;i=1+IntegerPart[(Locij-1) /NX]j=Mod[Locij-1, NX] +1Out[17]=1Out[18]=10ArrayPlot_DoubleLoop_TripleLoop.nb 7
In[15]:=(*Copy Method B implmentation from above-replace each i and j with its Locij parameterization*)Animate[ArrayPlot[Partition[Join[Array[1 &,(1+IntegerPart[(Locij-1) /NX] -1) *NX+(Mod[Locij-1, NX] +1) -1],{2}, Array[0 &, NX^2-((1+IntegerPart[(Locij-1) /NX] -1) *NX+ (Mod[Locij-1, NX] +1))]], NX],Mesh→True, ColorRules→ {1→Pink, 0→Yellow, 2→Gray}, ImageSize→200,PlotLabel→Style[StringJoin["{i,j} = {", ToString[1+IntegerPart[(Locij-1) /NX]],",", ToString[Mod[Locij-1, NX] +1], "}"], Black, 20]],{Locij, 1, NX^2, 1}, AnimationRunning→False]Out[15]=Locij{i,j} = {1,1}C) Triple-loop extension: Make ArrayPlot dynamic across all ijk valuesMethod A: Make a list of NX^3 plots - indicate k-value using variable border color8ArrayPlot_DoubleLoop_TripleLoop.nb
In[35]:=(*Make list of all images and store in variable called ArrayPlotij*)ArrayPlotij=ReapFork=1, k≤NX, k++,Fori=1, i≤NX, i++,Forj=1, j≤NX, j++,V1=Array[1 &,(i-1) *NX+j];(*Vector of 1s up to current i,j location*)V2=Array[0 &, NX^2- ((i-1) *NX+j)];(*Vector of 0s aftercurrent i,j location*)V12=Join[V1, V2];Matrix12=Partition[V12, NX];Matrix12〚i〛〚j〛 =2;(*Set current location i,j to 2*)(*From demo below-How to join two Style[]d strings*)PlotLabelijk=Apply[StringJoin, ToString[#, StandardForm]&/@ {"{i,j,k} = {",ToString[i], ",", ToString[j], ",", Style[ToString[k],Blend[{GrayLevel[0.9*k/NX], Green}, .3], Bold, Large], "}"}];Sow[ArrayPlot[Matrix12, Mesh→True,MeshStyle→Directive[Blend[{GrayLevel[0.9*k/NX], Green}, .2], AbsoluteThickness[8]],ColorRules→ {1→Pink, 0→Yellow, 2→Gray},ImageSize→300, PlotLabel→PlotLabelijk]];;;;〚2〛〚1〛;Length[ArrayPlotij]ArrayPlotij〚1〛Out[36]=1000ArrayPlot_DoubleLoop_TripleLoop.nb 9
Out[37]={i,j,k} = {1,1,1}In[26]:=Animate[ArrayPlotij〚Locij〛,{Locij, 1, NX^3, 1}, AnimationRunning→False]Out[26]=Locij{i,j,k} = {1,1,1}How to join two Style[]d stringshttps://mathematica.stackexchange.com/questions/10990/how-to-join-two-styled-strings10ArrayPlot_DoubleLoop_TripleLoop.nb