Prev: Epic Epic HeavisideTheta problem
Next: Fix for "Mathematica has quit unexpectedly" on Shift+Option start-up
From: nt on 5 Apr 2010 08:03 Hi all, I want to export a vector from a loop statement with two counting variables, i,j. as an example: w0=1;dk=1; eq= a function of w and k; Do[{w[i] = i*w0}; {eq1[i] =eq /. w -> w[i]}; {k[j] = j*dk}; b[i, j] = eq1[i]/.k-> k[j]}];bet[i] = Min[bet[i, j]], {i, 1, 5}, {j, 1, 5}] ; When I try to name the Do loop and export to excel, it exports the whole matrix with the size 5*5. How can I export the vector bet[i] from the loop?
From: Albert Retey on 6 Apr 2010 07:25 Hi, > I want to export a vector from a loop statement with two counting > variables, i,j. as an example: > > w0=1;dk=1; > eq= a function of w and k; > Do[{w[i] = i*w0}; {eq1[i] =eq /. w -> w[i]}; {k[j] = j*dk}; b[i, j] = > eq1[i]/.k-> k[j]}];bet[i] = Min[bet[i, j]], {i, 1, 5}, {j, 1, 5}] ; > When I try to name the Do loop and export to excel, it exports the > whole matrix with the size 5*5. > How can I export the vector bet[i] from the loop? I think you have sent this already and got a similar answer: If you expect people to help you, you should: a) take the time to learn at least the very basics of Mathematica b) send complete simplified examples that actually can be executed to see what the problem is. c) describe what it is that you try to achieve. d) avoid to make statements that are not true (Do does not return anything, and for sure it does not export as a 5*5 matrix to excel!) hth, albert
From: Bill Rowe on 6 Apr 2010 07:23
On 4/5/10 at 8:02 AM, sagittarius5962(a)gmail.com (nt) wrote: >I want to export a vector from a loop statement with two counting >variables, i,j. as an example: >w0=1;dk=1; eq= a function of w and k; Do[{w[i] = i*w0}; {eq1[i] = =eq >/. w -> w[i]}; {k[j] = j*dk}; b[i, j] = eq1[i]/.k-> k[j]}];bet[i] = >Min[bet[i, j]], {i, 1, 5}, {j, 1, 5}] ; When I try to name the Do >loop and export to excel, it exports the whole matrix with the size >5*5. How can I export the vector bet[i] from the loop? A key issue is bet[i] is not a vector in Mathematica. In Mathematica, this notation is the function bet evaluated at i. I can create a 2D list that can be seen as a matrix by doing: In[1]:= b = Table[10 i + j, {i, 3}, {j, 3}]; b[[2]] Then I can access the 2nd row by: Out[2]= {21,22,23} or the 2nd column by: In[3]:= b[[All, 2]] Out[3]= {12,22,32} and Export["filename.xls", b[[2]], "XLS"] will export just the second row to Excel. However, when done this way, the elements of b[[2]] will appear in a single column rather than a single row. If you want them in a single row then Export["filename.xls", List/@b[[2]], "XLS"] should do that. |