Cells showing up empty when using xlswrite or variable editor, but show proper data when referenced directly

1 view (last 30 days)
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
Taylor
Taylor on 3 Jul 2012
Here you go:
ans =
0
32
85
82
67
85
32
84
79
80
32
76
69
86
69
76
32
65
83
83
69
77
66
76
89
32
81
85
65
76
32
0
Writing that to URCU{3,3} seems to fix it, is there a function to write it back to a string?

Sign in to comment.

Accepted Answer

Walter Roberson
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);

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!