To write a string into an Excel cell in Matlab, you can use the xlswrite
function. This function writes a numeric or a cell array to an Excel file. To write a string, you have to pass it as cell array. Here's an example:
main.m186 chars8 lines
In this example, the xlswrite
function writes the cell array cellToWrite
to an Excel file named example.xls
, in the sheet named Sheet1
, starting from the cell A1
. The contents of the cell will be the string 'Hello, world!'
. Note that we passed the string as a cell array {stringToWrite}
.
You can also write multiple strings to different cells, by creating a larger cell array, where each element is a string:
main.m242 chars8 lines
In this example, the xlswrite
function writes a cell array with 7 elements to an Excel file named example.xls
. The cell array is created by the reshape
function, which takes a row vector of strings, and reshapes it to a column vector of cells. Finally, the cell array is written to the Excel file, starting from the cell A1
.
gistlibby LogSnag