
How to Save an Excel File in Octave
In this tutorial, I will walk you through the steps of saving a file in Excel format using Octave.
Let's start with a practical example.
First, create an array with some values.
>> M = [1 2 3; 4 5 6; 7 8 9]
M =
1 2 3
4 5 6
7 8 9
Next, assign a variable name to the Excel file you want to create.
>> filename = 'test2.xlsx';
Before we proceed, ensure that the io module is loaded in memory.
If you haven't loaded it yet, you can do so by typing:
pkg load io
Note. If you haven't installed the io module yet, enter the following command on the Octave console to install it by typing pkg install -forge io
Now, to write the array M to the 'test2.xlsx' file in Excel format, use the xlswrite() function.
In the parentheses, specify the variable that contains the file name and the array to be saved.
>> xlswrite(filename,M)
Octave will write the array to the specified file.
If you open the test2.xlsx file with Excel, you will see the array data displayed in the spreadsheet cells.
You have successfully saved the file in Excel format!
Note. To read the file in Excel format in Octave, use the xlsread() command.