Re: export mathematica table to .mat (MATLAB) format.Please help!!!
- To: mathgroup at smc.vnet.net
- Subject: [mg88752] Re: export mathematica table to .mat (MATLAB) format.Please help!!!
- From: "Szabolcs HorvÃt" <szhorvat at gmail.com>
- Date: Fri, 16 May 2008 05:27:54 -0400 (EDT)
- References: <g0h4k2$l9p$1@smc.vnet.net> <482C2783.5090906@gmail.com>
On Thu, May 15, 2008 at 2:22 PM, konstantinos mammasis <mammasis82 at hotmail.com> wrote: > Hi, > > thanks for your reply. Let me please explain in further detail. > > I am integrating a function many times. Every time the integral is evaluated > I store its output value in a Table. I want to export all the table values > to .mat format. So my code looks like this: > > Table[NIntegrate[ > Function[\[Theta], \[Phi]] > SphericalHarmonicY[n, m, \[Theta], \[Phi]], {\[Theta], > 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}], {n, 0, 20}, {m, -n, n}] > MatrixForm[%] This command does not have a correct syntax and cannot be evaluated without errors, so I'm not sure what your data looks like exactly. But it seems that we are working with 2-level lists, so we just need to pad it. > > As you can understand from my code for each value of n,m I want to evaluate > this integral and store the output. A few months ago I was advised to use > the Table function in order to do this. However, now that I want to export > this table I get problems. > > Do you have any suggestions? > > You are right that my matrix is not "quite" a matrix as we know it. However, > perhaps there is a way to fill in the empty entries with zeros. I don't know > how to do it. > If we have a ragged array, such as data = Table[i + j, {i, 1, 5}, {j, 1, 2 i}] , we can pad it with zeros using PadRight: PadRight[data, {Length[data], Max[Length /@ data]}] This will give return a matrix that can be exported to .mat format.