필터 지우기
필터 지우기

How do you write to excel a cell array that contains both strings and numbers?

조회 수: 16 (최근 30일)
I have to write a relatively large cell array to excel. The text is primarily column headers but the data does have some text intertwined in it. Is there a simple way to do this?
I've done some digging but most everything I've found says use fprintf and specify when data is of a specific type. This data is too large to run something like that.
The text data is in specific columns, if there were a way to identify text data as strings and just tell MATLAB that all other fields are numeric, that's viable.

답변 (2개)

Guillaume
Guillaume 2017년 6월 2일
Just pass your cell array to xlswrite, nothing more complex.
%simple demo
c = {'abcd', 1234; 'foobar', -56}
xlswrite('test.xlsx', c);
I don't know where you've seen most everything that says use fprintf. You cannot write excel files with fprintf which is for writing text files. Excel files are binary (or in newer versions, a complex mess that you'd never write yourself as text).
  댓글 수: 1
Avery Krovetz
Avery Krovetz 2017년 6월 2일
I'm running R2016b. that code generates the warning:
Could not start Excel server for export. XLSWRITE will attempt to write file in CSV format.
Then the error:
An error occurred on data export in CSV format.

댓글을 달려면 로그인하십시오.


Fangjun Jiang
Fangjun Jiang 2017년 6월 2일
As long as each cell is a single scalar or a single string, what is wrong with using xlswrite() directly?
TestData={'a',1;2,'b'};
xlswrite('ExcelFile',TestData);
  댓글 수: 1
Jacinta Cleary
Jacinta Cleary 2018년 10월 8일
I'm not sure if its a Mac thing (I think I saw that somewhere) but it doesn't seem like xlswrite can write text and data together. I've been trying to get this to work for a while. Does anyone have any updates?
Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by