Domanda

Could someone assist in writing a char matrix to Excel? The following is a <17x6 char>

A =

SPK01a
SPK03a
SPK03b
SPK05a
SPK07a
SPK07b
SPK07c
SPK09a
SPK11a
SPK15a
SPK17a
SPK19a
SPK21a
SPK23a
SPK25a
SPK27a
SPK29a

I was trying to do xlswrite(filename, {A}) but receive the error:

Error using xlswrite (line 220)
ActiveX - Element of a cell array cannot be a character matrix.

I need the strings to be in cells, so in this case, in the first column in Excel, in 17 separate cells.

È stato utile?

Soluzione

You can use cellstr to make a properly shaped cell array:

xlswrite(fileName,cellstr(A))

cellstr provides a quick way to place each row of a character array into a separate cell, and it will remove trailing spaces at the end of each row.

Altri suggerimenti

Use mat2cell to convert your matrix of characters into a cell array and use that to write into an excel file -

xlswrite(xls_filename,mat2cell(A,ones(1,size(A,1))))

This will write everything to the first column of the excel sheet, but in different rows.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top