Plotting six chosen rows of a matrix - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-21T20:17:20Z https://mathematica.stackexchange.com/feeds/question/79796 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/79796 0 Plotting six chosen rows of a matrix johnhenry https://mathematica.stackexchange.com/users/27673 2015-04-13T17:10:46Z 2015-04-13T18:34:55Z <p>I have a matrix,<code>W</code>, whose dimension is <code>n x n</code>, each entry is a number. I need to plot only the values of six rows, namely those labelled by the row index <code>i</code> equal to:</p> <pre><code>n/32, 3*n/64, n/16, 3*n/32, n/8, 3*n/16, n/4, 3*n/8 </code></pre> <p>For every row I need to plot all of the <code>n</code> values that are in the row. I should end up with six plots, hopefully all in the same page. I guess I should use ListLinePlot, but how exactly can I do that?</p> <p>EDIT: instead of using the value of <code>i</code> mentioned before, I am now using <code>i</code>= 1,2,3,4, just to practise. I am following @belisarius advice, using:</p> <pre><code>l = {1, 2, 3, 4}; ListLinePlot[W[[l]], PlotLegends -&gt; l] </code></pre> <p>to plot the 4 graphs. But I keep having the following error:</p> <pre><code> Part {1,2,3,4} of (&lt;&lt;1&gt;&gt;) does not exist. </code></pre> <p>Why does this happen and how can I fix it?</p> <p>EDIT: Here is my whole code. The problem is in the <code>Wab</code> matrix, which seems not to make sense, as I cannot plot the desired values mentioned above.</p> <pre><code>getA[kappa_] := Table[2*Cos[(2*Pi/n)*(Abs[j - i])*kappa], {i, n}, {j, n}]; getF[csi_, a_, b_] := Module[{csiInv = Inverse[csi]}, .5 Tr[csiInv.a.csiInv.b]]; getG[csi_, f_, a_] := Module[{csiInv = Inverse[csi]}, csiInv.a.csiInv/2]; getE[g_, k_] := Module[{kinv = Inverse[k]}, Transpose[kinv].g.kinv]; getW[k_, a_, e_] := Module[{ktrans = Transpose[k]}, Tr[k.a.ktrans.e]]; getV[csi_, e_, e2_, k_] := Module[{ktrans = Transpose[k], e2trans = Transpose[e2]}, 2*Tr[csi.ktrans.e.k.csi.ktrans.e2trans.k]]; getP[g_, delta_] := Module[{deltatranspose = Transpose[delta, {1}]}, deltatranspose.g.delta]; n = L = 16; sigma = 3; nyquist = n/2 + 1; sampling = 8; mu = 0.0; powerspectrum[i_] := Piecewise[{{0, i == 0}, {Exp[-(2*Pi*i*sigma/L)^2], 0 &lt; i &lt;= n/2}, {Exp[-(2*Pi*(n - i)*sigma/L)^2], n/2 &lt; i &lt;= n}}]; pts = Table[powerspectrum[i], {i, 0, n - 1}] ; inverse = InverseFourier[pts]; func[inverse_] := Module[{n = Length[inverse], tup}, tup = Cases[ Tuples[Range[n], 2], {i_, j_} /; Abs[i - j] &lt; (n - 1)/2]; SparseArray[ Thread[tup -&gt; (inverse[[Abs[#1 - #2] + 1]] &amp; @@@ tup)], {n, n}]]; CSI = func[inverse]; Kmatrix = Table[((3.0*70.0*70.0*0.3)/(2.0*300000.0*300000.0))*((j + 1)*(i + 2 - (j + 1)))*(1.0 + (70.0/300000.0)*(j + 1)), {i, 0, n - 1}, {j, 0, n - 1}]; leftREAL = Table[RandomVariate[ NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]], {k, n/2}]; rightREAL = Reverse[leftREAL] /. {x_, y_} -&gt; {n - x, y}; fullREAL = Join[{0.0}, Most[leftREAL], rightREAL]; leftIMAGINARY = Table[RandomVariate[ NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]], {k, n/2 - 1}]; rightIMAGINARY = -Reverse[leftIMAGINARY] /. {x_, y_} -&gt; {n - x, y}; fullIMAGINARY = Join[{0.0}, leftIMAGINARY, {0.0}, rightIMAGINARY]; fullfield = fullREAL + I*fullIMAGINARY; fieldconfiguration = InverseFourier[fullfield]; Wab = Table[ getW[Kmatrix, getA[beta], getE[getG[CSI, getF[CSI, getA[alpha], getA[alpha]], getA[alpha], Kmatrix]]], {alpha, n}, {beta, n}]; </code></pre> https://mathematica.stackexchange.com/questions/79796/-/79797#79797 2 Answer by Dr. belisarius for Plotting six chosen rows of a matrix Dr. belisarius https://mathematica.stackexchange.com/users/193 2015-04-13T17:20:09Z 2015-04-13T17:29:52Z <pre><code>n = 64; l = {n/32, 3*n/64, n/16, 3*n/32, n/8, 3*n/16, n/4, 3*n/8}; m = RandomReal[{0, 1}, {n, n}]; ListLinePlot[m[[l]], PlotLegends -&gt; l] </code></pre> <p><img src="https://i.stack.imgur.com/usbNe.png" alt="Mathematica graphics"></p>