writing a string to an excel file

I want to write strings to an excel file. Because I need to do this frequently I think I need to first write to a matrix and then write the matrix to the excel file. I can write numerical matrices to excel files using xlswrite. I have not figured out how to do this with strings.
For example I want to write 'CL on' and then some time later write 'CL off'
Thanks for your help.

답변 (1개)

Walter Roberson
Walter Roberson 2011년 8월 2일

1 개 추천

Are you using Windows and do you have Excel installed? If so then you can xlswrite() a cell array that can have string or numeric entries or a mix.
If you are not using Windows or Excel is not installed, then xlswrite() will not accept a cell array and you must use other ways to write the data.

댓글 수: 3

Jim
Jim 2011년 8월 3일
Thank you Walter for replying promptly. Yes, I am using Windows XP and Excel 2003 is installed.
My code for writing string 'CL off' onto sheet "inter" in filename.xls:
Datainter(1:2500,1:2) = 0;
<code that produces a string>
Datainter(1,1) = 'CL off';
xlswrite('filename.xls',Datainter, 'inter');
This produces an error "??? Subscripted assignment dimension mismatch."
What is the correct code to do this?
Fangjun Jiang
Fangjun Jiang 2011년 8월 3일
First you assigned Datainter as an all-zero double array. They you tried to assign a string to the first element. That is not allowed. You need to learn how to use cell array. help cellstr
C = {'hello' 'yes' 'no' 'goodbye'}
xlswrite('test.xls',C);
Walter Roberson
Walter Roberson 2011년 8월 3일
Datainter{1:2500,1:2} = 0;
Datainter{1,1} = 'CL off';
Notice the use here of cell arrays, {} instead of ()

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

카테고리

태그

질문:

Jim
2011년 8월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by