MATLAB: Unknown character element (after import from binary)

binaryblank elementscharacteremptyempty spacesimportnulnullunknown character

Hello,
I have been importing character strings from a binary file, which are results from a command such as:
file = 'I:\20130212_Umean_grid_RE\ExportedData\MatlabTestOnePositionAllProbes.bin';
fileID = fopen(file,'r','n');
fseek(fileID, 10, 'bof');
DatabaseName = fread(fileID,128,'char=>char')';
As result I receive DatabaseName as…
DatabaseName =
F:\20130212_UMEAN_GRID_RE\20130212_UMEAN_GRID_RE.SDB
Now the problem is: DatabaseName is a 1×128 char whereas the first 51 elements (of course this is varying and I don't know that before) are those I am actually interested in and the last 77 elements are absolutly unknown characters, which react on the following commands with
isspace(DatabaseName(end))
ans =
0
ischar(DatabaseName(end))
ans =
1
if DatabaseName(end) == ''
DatabaseName(end) = []
end
DatabaseName –> still (1×128 char)
So the problem I actually have is that I don't find any possibility to compare for those "imaginary/unknown spaces/elements"… so I could delete those with a simple for-loop. Commands such as
strtrim
deblank
don't work obviously because these are based on
isspace == 1
which is not the case for these symbols…
I already opened the binary file with a hex editor and found out that those empty chars are created from 8 bit / 1 byte sequences from the binary file with the binary code "00000000", which corresponds to nul/null in the extended ascii code…
But how is it possible to delete those last elements from the string? How can I look for "nul" in a character string in MATLAB?
Thanks in Advance,
Philipp

Best Answer

I'm surprised that isspace(char(0)) is not TRUE. What about:
Str(Str == char(0)) = [];
Or
Str = Str(Str >= char(32) & Str <= char(127)); % [EDITED && -> &]