フィルターのクリア

How can I put single quotes inside single quotes?

31 ビュー (過去 30 日間)
Daniel
Daniel 2022 年 12 月 8 日
コメント済み: Daniel 2022 年 12 月 8 日
vector = ['a', 'b', 'c','d', '1', '2', '3', '!', '@', ' " ', ''' ];
in the above code segment the vector contain different elements but the last element which is single quote is not placed properly. so, how can i put it correctly?
  1 件のコメント
Stephen23
Stephen23 2022 年 12 月 8 日
Square brackets are a concatenation operator, so this code:
V1 = ['a', 'b', 'c', 'd', '1', '2', '3', '!', '@', '"', '''' ]
is exactly equivalent to (but a pointlessly long and complex way of) simply writing this:
V2 = 'abcd123!@"'''
How to escape single quotes in character vectors is explained in the MATLAB documentation:
"If the text includes single quotes, use two single quotes within the definition."

サインインしてコメントする。

採用された回答

DGM
DGM 2022 年 12 月 8 日
You can escape single quotes with another single quote. For sake of clarity, I'm going to transpose the output.
vector = ['a', 'b', 'c','d', '1', '2', '3', '!', '@', '"', '''' ].'
vector = 11×1 char array
'a' 'b' 'c' 'd' '1' '2' '3' '!' '@' '"' '''
  1 件のコメント
Daniel
Daniel 2022 年 12 月 8 日
Thank you Sir.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by