remove the functionality of special characters

10 次查看(过去 30 天)
I have a cell array that contains the '%' character
C = {000000020F0D0%, 0000000281830%, 0071803F01CF0%, 0071803F6AA40%};
the problem is that it commnets out everything after it. How do I avoid this?

采纳的回答

John D'Errico
John D'Errico 2019-12-30
编辑:John D'Errico 2019-12-30
What do you think the % symbol does in MATLAB? Answer: when not inside quotes (so a string) it creates a comment.
What do either of these strings of characters mean in MATLAB?
000000020F0D0
000000020F0D0%
Answer: Essentially nothing. It is just a list of characters. Inside a cell array as you are trying to put it, they do not even form a valid MATLAB syntax.
I might guess that perhaps you want them to be strings of some ilk, representing whatever it is you want them to mean, thus:
C = {'000000020F0D0%', '0000000281830%', '0071803F01CF0%', '0071803F6AA40%'};
But as you want to create that cell array, it is just a syntax error waiting to happen.
You cannot arbitrarily turn off the functionality of a % in MATLAB, any more than you can hope that MATLAB will know what it is that you might want MATLAB to do with that statement.
Since you appear to be creating these statements, then you probably need to create them as strings, thus with enclosing quotes, IF you want to create them as cell arrays.

更多回答(1 个)

Jonah Pearl
Jonah Pearl 2019-12-30
What are the % signs for? I think you can just make the contents of the cell array into characters:
C = {'000000020F0D0%', '0000000281830%', '0071803F01CF0%', '0071803F6AA40%'};
If you ever need to get just the part out before the % sign, you can use regexp:
part = regexp('000000020F0D0%', '(\w*)%', 'tokens');
  1 个评论
avram alter
avram alter 2019-12-30
编辑:avram alter 2019-12-30
those signs are part of an incoming serial tag. they are a necessary part of the tag's identity.
thanks for the help, it's a bit of an obvious question, but I am not very good at this.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by