MATLAB: Remove all the spaces from a string.

forisspacemat2str

I have a string:
Pre_CRC = '[1 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0]'
I need to convert this into a string to convert it into a unintialized binary number.
A = [msg_FCS(1,16385),msg_FCS(1,16386),msg_FCS(1,16387),msg_FCS(1,16386),msg_FCS(1,16387),...
msg_FCS(1,16388),msg_FCS(1,16389),msg_FCS(1,16390),msg_FCS(1,16391),msg_FCS(1,16392),...
msg_FCS(1,16393),msg_FCS(1,16394),msg_FCS(1,16395),msg_FCS(1,16396),msg_FCS(1,16397),...
msg_FCS(1,16398),msg_FCS(1,16399),msg_FCS(1,16400)];
Pre_CRC = (mat2str(A));
Trim_CRC = zeros(1,16);
Trim_CRC_Counter = 1;
for dd = 1:length(Pre_CRC)
if (isspace(Pre_CRC(:,dd)) == 1)
Pre_CRC(:,dd) = [];
else
Pre_CRC(1,dd) = Trim_CRC(1,Trim_CRC_Counter);
Trim_CRC_Counter = Trim_CRC_Counter + 1;
end
end
The end needs to be a string with the binary values that I can convert to a decimal or hex number. The two for loop above is giving me a matrix out of bounds errors. Can anyone help me fix this?
Thanks !

Best Answer

Pre_CRC(isspace(Pre_CRC)) = []
Related Question