remove the functionality of special characters

9 ビュー (過去 30 日間)
avram alter
avram alter 2019 年 12 月 30 日
編集済み: John D'Errico 2019 年 12 月 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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by