dimwrite and zeros

조회 수: 1 (최근 30일)
huda nawaf
huda nawaf 2011년 12월 9일
hi, if I want store matrix in file with columns have different lengths using dlmwrite, can dlmwrite store just numbers without store zeroes?
I have beg size matrix (crazy matrix)with different lengths of columns thanks

답변 (2개)

Walter Roberson
Walter Roberson 2011년 12월 9일
dlmwrite can only store numbers or characters (but not any mix of the two.) It is not suitable for intermediate blank columns, and it is not suitable for rows or columns of different length.
It is pretty much the case that dlmwrite is only suitable for writing plain rectangular numeric arrays.
If you are using MS Windows and you have Excel installed, then you can use xlswrite() to write cell arrays.
If you are using any other operating system or do not have Excel installed, then it is usually much easier to use fopen() / fprintf() / fclose() to create your file.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 12월 9일
xlswrite() would normally be used to create .xls files (or .xlsx or the like), which are binary or structured file formats, not simple text files.
You would use xlsread() or a COM object to read .xls files.
If you need to use the file as a text file specifically, then you would be better off writing the file using fprintf as outlined above.
huda nawaf
huda nawaf 2011년 12월 10일
thanks,
I did that ,but what is the benefit from xsl file? it is also save zeros
these zeros enlarge my files
where become very big, and I can not open it.
Look , I need a way to save array have columns with different lengths such do not save zeros .
ex. x= 1 2 3 4 100 0 0 0
1 4 1 3 4 1 2 3
2 3 4 5 6 1 2 0
I do not want these zeros in end of each row because of enlarge size of my files.
my data do not contain zeros except in end of row.
please walter help me

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


Andrei Bobrov
Andrei Bobrov 2011년 12월 10일
x= [1 2 3 4 100 0 0 0
1 4 1 3 4 1 2 3
2 3 4 5 6 1 2 0]
xc = num2cell(x);
xc(cellfun(@(x)x==0,xc)) = {[]}
xlswrite('xlstst',xc)
  댓글 수: 1
huda nawaf
huda nawaf 2011년 12월 10일
thanks,
I have two notes
the first: I checked the size of file in both cases (save with zeros and without zeros) and find out the both files with same size.
the second note: when try
x=magic(1000);
>> x(1:100,:)=0;
>> xc = num2cell(x);
>> xc(cellfun(@(x)x==0,xc)) = {[]};
>> xlswrite('xls2',xc)
??? Error using ==> xlswrite at 211
Excel returned: Error: Object returned error code: 0x800A03EC.
why this error?

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

카테고리

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