Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I search the forum and found a question about exporting interpolating functions to excel. Unfortunately, I can't use it to export the results to excel. This is the equation :

u = StateResponse[ssm, UnitStep[t] , {t, 0, 1},Method -> {"NDSolve", MaxSteps -> 1600000}]

and the answer is :


I would appreciate that someone can help me to export this equation to a excel file.

share|improve this question
Seems to be a duplicate of… – PlatoManiac Aug 28 '13 at 13:41
@ PlatoManiac : Unfortunately, It's not possible for me to mention my ` ssm ` .Beside that,if I could do that, my ` ssm ` would be a huge matrix that I wouldn't be able to provide it here. – Shield Aug 28 '13 at 13:54
When I use the procedure mentioned in `… `, it give me a Excel file only with 2 data!! – Shield Aug 28 '13 at 13:58
up vote 3 down vote accepted

I think the solution to your problem is implicitly hidden in here as I mentioned in the comment.Lets take an example problem!

res = StateResponse[
StateSpaceModel[{{{-3, 3/2, -1}, {-2, 1, -2}, {-1, 3, -2}}, {{1,0}, {1, -1}, {1, 1}},
{{1, 0, -1}}, {{0, 0}}}, 
SamplingPeriod -> None,SystemsModelLabels -> None], {SquareWave[t], Sin[t]}, {t, 0, 20}];

Also assume that the following is a summation expression you are interested in.

exp = Total[res^2 RandomReal[1, {3}]]

0.977826 InterpolatingFunction[{{0.,20.}},<>][t]^2+0.455719 InterpolatingFunction[{{0.,20.}},<>][t]^2+0.943215 InterpolatingFunction[{{0.,20.}},<>][t]^2

Now we export the expression exp defined in terms of InterpolatingFunction to an Excel data file as below

fun[k_] := exp /. t -> k;
tval = Range[0, 20, .01]; (*How often you want to record the values*)
Export[FileNameJoin[{$UserDocumentsDirectory, "sol.xlsx"}],Transpose@{tval,fun/@tval}];

Now test if things are working fine. Left one is directly from Mathematica and the right one after importing from the excel file we generated above followed by a consecutive interpolation.

impfun = Interpolation[
First@Import[FileNameJoin[{$UserDocumentsDirectory, "sol.xlsx"}],"Data"]];
GraphicsRow[Plot[#[t], {t, 0, 20}, Frame -> True] & /@ {fun, impfun},ImageSize -> 600]

enter image description here

share|improve this answer
@ PlatoManiac : It works my friend!! I really appreciate you for it. – Shield Aug 28 '13 at 14:39
You are welcome. The trick if you are new with Mathematica is be persistent and do not loose hope quickly! – PlatoManiac Aug 28 '13 at 14:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.