remove all the spaces from a string.
3 次查看(过去 30 天)
显示 更早的评论
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 !
1 个评论
Jan
2012-7-30
As usual: Please post the complete error message an the line, which causes the problems. It is always a good idea to let the contributors guess as less as possible.
采纳的回答
更多回答(1 个)
Jan
2012-7-30
编辑:Jan
2012-7-30
Look what this code does:
for dd = 1:length(Pre_CRC)
if (isspace(Pre_CRC(:,dd)) == 1)
Pre_CRC(:,dd) = [];
Pre_CRC(:,dd) is a vector, as far as I can see. Therefore isspace(Pre_CRC(:,dd)) will be a vector also. Comparing its elements with 1 will not change anything, such that this can be omitted. The if command inserts an all implicitly, if it gets a vector as input. Is this the intended behavior?
Now imagine the above works. Then Pre_CRC(:,dd) = []; removed an element from Pre_CRC. This means that Pre-CRC gets shorter, but the for dd loop runs still until the original length!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!