How to Write Data to Excel Spreadsheets in MATLAB?
Last Updated :
26 Apr, 2025
MATLAB provides options to write a table, array, or matrix to Microsoft Excel spreadsheets. The function available to do so is the writetable () function. The general syntax for this function is:
Syntax:
writetable(<data>, <filename>, <optional_values>)
Now, in the following sections, we shall see how to write a table, an array, and a matrix into a spreadsheet.
Writing a Table to Excel Spreadsheet:
Firstly, we shall create a table and then write the same to an excel spreadsheet with the help of writetable function.
Example 1:
Matlab
% MATLAB Code
tab = magic(5);
tab = array2table(tab,"VariableNames",
["R1" "R2" "R3" "R4" "R5"]);
disp(tab)
% Writing the table to excel file
writetable(tab,'new.xls','FileType','spreadsheet')
The output of the above code will create a new excel sheet in the current folder.

In the above code, we create a table from magic with the variable names or table headers passed as a vector. Then, in the writetable function, we pass the table, and the file name to be used (if present then, it'll overwrite the data. If not, then it will create a new file and then, it'll create a new file). The next argument is a field type that decides the file type and the argument following it is the value for the same field; spreadsheet in this case.
Writing a Matrix to Excel Spreadsheet
In the above section, we discussed how to add a table to an excel sheet. In this section, we shall explore the writetable further by adding a matrix at specified cells in a spreadsheet. Let us see the same with the help of an example.
To write numeric data into an excel sheet, we need can use the writetable function. We have to use another function, the writematrix function.
writematrix(<data>, <filename>, <optional_values>)
The syntax is the same as the writetable just the datatype changes to double, float, or int.
Example 2:
Matlab
% MATLAB Code
tab = magic(5);
% Using the writematrix to write
% numeric data at specific location.
writematrix(tab,'new.xls','Sheet',2,'Range','C1')
Output:

In this code, we write the magic square matrix to an excel spreadsheet named new.xls. The following arguments define the sheet number and the starting cell where we want to write our matrix-formed data.
Writing a cell array (array of multiple data types) to an excel spreadsheet
To write an array with both numeric and text data, we use the writecell() function. The syntax of the same is similar to writematrix and writetable however, the data type then changes to a cell array.
writecell(<data>, <filename>, <optional_values>)
In the following example, we will write a cell array to a new sheet in our new.xls spreadsheet.
Example 3:
Matlab
% MATLAB Code
arr = {'cell', 'array'; 1, 2; 23, 31};
% writing cell array to a reduced range
writecell(arr,'new.xls','Sheet',3,'Range','C1:E2')
Output:

In this code, we are writing a 3x3 cell array to the spreadsheet in sheet 3 from a range of cells C1 to E2, this means that only as many elements as are specified in the range C1:E2.
Similar Reads
How to Write Pandas DataFrames to Multiple Excel Sheets?
In this article, we will see how to export different DataFrames to different excel sheets using python. Pandas provide a function called xlsxwriter for this purpose. ExcelWriter() is a class that allows you to write DataFrame objects into Microsoft Excel sheets. Text, numbers, strings, and formulas
6 min read
Write Data to Text Files in MATLAB
Writing data to a text file means creating a file with data that will be saved on a computer's secondary memory such as a hard disk, CD-ROM, network drive, etc. fprintf() function is used to write data to a text file in MATLAB. It writes formatted text to a file exactly as specified. The different e
3 min read
How to Create Multiple Sheets in Excel workbook Using R
In this article, we will discuss how to create multiple sheets in an excel file using the xlsx package. As we all know in general an excel file might contain one or more than one sheet present in it. Manually we can create and insert data into multiple sheets in Excel GUI Application but when it co
2 min read
How to read a XLSX file with multiple Sheets in R?
In this article, we are going to see how to read an XLSX file with multiple Sheets in R Language. There are various external packages in R used to read XLSX files with multiple sheets. File Used: Method 1: Using readxl package The readxl package in R is used to import and read Excel workbooks in R,
5 min read
What is a Excel Spreadsheet
If you search only about Spreadsheet then you will find it is a computer applicaion that save, display, and manipulate data in rows and columns. In the year 1978 first spreadsheet program is developed by Daniel Bricklin and Bob Frankston named as VisiCalc. Now, in the recent year Microsoft Excel is
12 min read
How to plot excel data in R?
Plotting graph in R using an excel file, we need an excel file with two-column in it, the values in the first column will be considered as the points at the x-axis and the values in the second column will be considered as the points at the y-axis. In this article, we will be discussing the approach
2 min read
Export Dataframes to Multiple Excel Sheets in R
An excel workbook is used to contain tabular information stored within a cell-like structure. Every excel workbook in R contains multiple sheets to contain the data belonging to the same domain information. The excel sheet can contain columns belonging to different data types. The Excel files can be
5 min read
How to Convert HTML Table into Excel Spreadsheet using jQuery ?
In this article, we will learn how we can convert an HTML table into an Excel spreadsheet using jQuery. There are two ways available in jQuery to accomplish this task as discussed below:Table of Content Using the jQuery table2excel pluginBy creating the file download link in excel formatApproach 1:
3 min read
Loading Excel spreadsheet as pandas DataFrame
Pandas is a very powerful and scalable tool for data analysis. It supports multiple file format as we might get the data in any format. Pandas also have support for excel file format. We first need to import Pandas and load excel file, and then parse excel file sheets as a Pandas dataframe. Python3
1 min read
How to Record a Macro in Excel
Excel Macro is simply a record button that records a set of actions performed on Excel that can be run multiple times. For example, if you have to format some raw data on a weekly basis you can use a macro to record yourself formatting the data once and let Excel automate the task in the future. it'
11 min read