Borrar filtros
Borrar filtros

help with xlswrite

12 visualizaciones (últimos 30 días)
Abra dog
Abra dog el 1 de Nov. de 2011
Comentada: YUN ZHAO el 21 de Jul. de 2020
I'm trying to put a column of words and a column of numbers together on a excel spread sheet. I wrote:
G = column of words
F = column of number
xlswrite('filename',G,F)
Matlab returns with the error:
??? Error using ==> xlswrite at 179
An error occurred on data export in CSV format.
Caused by:
Error using ==> dlmwrite at 112
The input cell array cannot be converted to a matrix.
Is there anyway for me to do this without turning the words into numbers with dlmwrite?

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Nov. de 2011
Editada: John Kelly el 27 de Feb. de 2015
If xlswrite() delegated to dlmwrite() then the implication is that you are either not using an MS Windows machine or else that you do not have Excel installed. In such cases, xlswrite() is restricted to writing numeric arrays.
It is possible to write text using dlmwrite(), by submitting an array of pure characters and using a character format in the Precision parameter and setting the delimiter to be empty.
But if you are going to do that then you might as well follow the recommendations linked to in the dlmwrite documentation to use low-level operations: http://www.mathworks.com/help/matlab/ref/dlmwrite.html
  4 comentarios
Abra dog
Abra dog el 1 de Nov. de 2011
if i typed the code even with the error can i still use the code on a PC?
Walter Roberson
Walter Roberson el 2 de Nov. de 2011
I do not understand that question.
The first argument to xlswrite() must be a file name. The second argument must be a numeric array (all versions) or alternately a cell array (MS Windows with Excel installed only). The third argument if provided must be the sheet or range specification.
A range specification must be a string, and your G is not a string, so your G cannot act as a range.
A sheet specification can be a string, or a scalar positive integer value that specifies the sheet index. If your G *happens* to consist of a single entry that is a positive integer, then it would be accepted as a range, but if your G is 0 or negative or is not a scalar value, then your G would not be accepted as a range.
On systems other than MS Windows, or on MS Windows systems that do not have Excel installed, the sheet and range would be ignored; those on those systems your G would be ignored. On MS Windows systems with Excel, if your G did not happen to be a positive integer, then you would get an error.
Your xlswrite() call as written is thus unlikely to work on any system: on MS Windows systems with Excel it is going to error because of the G, and on anything else it is going to error because on those systems xlswrite() cannot write character arrays.

Iniciar sesión para comentar.

Más respuestas (2)

Xing Zhang
Xing Zhang el 17 de Feb. de 2013
But I do have Microsoft Office 2011 for Mac installed on my Macbook Pro 15 inch, with Mountain Lion installed, and I am having exactly the same problem.
The code is running with no problem in my HP PC (Windows 8, Matlab 2012b), but when I run this code in Macbook Pro (Mountain Lion 10.8.2, Matlab 2012b) I got the same error.
Can someone help shoot this bug?
Thanks
  1 comentario
Walter Roberson
Walter Roberson el 17 de Feb. de 2013
xlswrite() can only communicate directly with Excel on MS Windows.
On machines with other operating systems no matter what they have installed, or on MS Windows machines that do not have Excel installed, xlswrite() is restricted to "basic" mode, which can only handle numeric arrays.

Iniciar sesión para comentar.


Stacey
Stacey el 9 de En. de 2020
From 2013b up, you can use writetable instead:
col_num = [1;2;3]
col_word = ['a';'b';'c']
writetable(table(col_num,col_word),'filename.xlsx')
  1 comentario
YUN ZHAO
YUN ZHAO el 21 de Jul. de 2020
It's working for me. Much appreciate!

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by