Filter löschen
Filter löschen

remove the functionality of special characters

9 Ansichten (letzte 30 Tage)
avram alter
avram alter am 30 Dez. 2019
Bearbeitet: John D'Errico am 30 Dez. 2019
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?

Akzeptierte Antwort

John D'Errico
John D'Errico am 30 Dez. 2019
Bearbeitet: John D'Errico am 30 Dez. 2019
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.

Weitere Antworten (1)

Jonah Pearl
Jonah Pearl am 30 Dez. 2019
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 Kommentar
avram alter
avram alter am 30 Dez. 2019
Bearbeitet: avram alter am 30 Dez. 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by