Cells showing up empty when using xlswrite or variable editor, but show proper data when referenced directly
1 view (last 30 days)
Show older comments
So I'm having a pretty strange problem. I wrote a program that goes through a folder structure and gets data from quite a few excel spreadsheets so I can consolidate all that information into one excel file.
The program works properly, but Matlab seems to be behaving very strangely for some cells. It's a little bit hard to put into words, so here'sa screenshot of the issue I'm having:
Some entries work perfectly fine:
Does anyone have an idea as to what is causing this, or how I could fix it? I initially thought it was an issue with xlswrite, but that is apparently not the case.
Thanks,
Taylor
2 Comments
Walter Roberson
on 3 Jul 2012
Could you show us
0 + URCU{3,3}
This will show the numeric codes for each character.
Accepted Answer
Walter Roberson
on 3 Jul 2012
The 0 that shows up at the beginning and end of the 0+URCU{3,3} indicates that somehow NUL characters got into the strings. MATLAB is a little inconsistent about what it does when NUL characters are present, but the more common behaviour for it is to believe that it has reached the end of the string.
The reason NUL characters are a problem is that parts of MATLAB are written using C or C++, and C and C++ treat NUL characters as terminating strings. MATLAB does not use NUL termination for strings, but as soon as the strings get sent through one of standard I/O libraries, there is a problem.
If you do not need the NUL characters to be there, best get rid of them:
URCU = cellfun( @(S) S(S~=0), URCU, 'Uniform', 0);
2 Comments
More Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!