How to insert Excel formula through Matlab?

We have discussed a number of programming tips especially on report generation using Microsoft Excel using Matlab. If you have not seen the article, you can refer to my articles on how to read and write a Microsoft Excel file. In this tutorial, we will see how to insert an Microsoft Excel formula through Matlab.

We have often seen, we need to do lot of report generation, when doing data analysis using Matlab and use Microsoft Excel for report generation. I have noticed that lot of people, just compute the result in Matlab and enter the result as data in Microsoft Excel file. However, it is also possible to insert Excel formula through Matlab. We will consider a simple example where we enter the data from Matlab into an Excel file and insert formula.

Example : Let’s say we have the data from some experiment and we will write this data in Excel and then insert the formula ( MAX) using Matlab.



Step 1: The first step is to create a COM server which runs the Excel Application:

Step 2
: In this step, we will open an Excel file “ResultFile.xls” in the current directory and set the visibility to true.

Step 3
: In this step, we will insert the data saved in the Matlab array ‘ResultData’. The following code will insert the data in column A.

Insert Excel formula through Matlab

We need to insert the Excel formula to compute the maximum of the experimental values. You can also use the max command in Matlab to obtain the maximum of the array of values. The Excel formula to compute the Maximum of the range of data is given by

Step 4
: In this step, we will insert the Excel formula which will compute the Maximum of the data range from cell A1 to A10.

Here xlcolumn() function converts between column name and number for Excel representation. The xlcolumn() module can be downloaded from here.


The complete source can be downloaded from here.

I hope, you find this article very useful. If you have any doubts or have any comments concerning this tutorial, Please leave a comment or contact me. I would be glad to help.

Kiran Chandrashekhar

Hey, Thanks for dropping by. My name is Kiran Chandrashekhar. I am a full-time software freelancer. I love Maths and Mathematical Shortcuts. Numbers fascinate me. I will be posting articles on Mathematical Shortcuts, Software Tips, Programming Tips in this website. I love teaching students preparing for various competitive examinations. Read my complete story.


  1. Hi there, I have noticed that sometimes this webpage renders a 404 server error. I thought that you would be keen to know. All the best

  2. Thanks for a marvelous posting! I definitely enjoyged reading it, you are a great author.
    I will remember to bookmark your blog and will eventually come back someday.
    I wanjt to encourage you to definitely continue your great job, have a nicde afternoon!

Leave a Reply

Your email address will not be published. Required fields are marked *

Protected by WP Anti Spam