how to add single quotes ' ' in a string?

45 ビュー (過去 30 日間)
GreyHunter
GreyHunter 2020 年 10 月 8 日
コメント済み: GreyHunter 2020 年 10 月 8 日
I am trying to add into my signal 2 quote marks. for example:
signal.wav and I would like to change it likes this: 'signal.wav'
I have done this so far:
a=strcat(signal_data,'.wav'); which gives me a=signal.wav
bear in mind that the signal name is keep chaning as it is in loop.
signal.wav
fun.wav
example.wav

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 8 日
Not sure why you would want something like that. Following works
signal_data = 'signal';
a=strcat('''', signal_data,'.wav''');
Result
>> disp(a)
'signal.wav'
  10 件のコメント
Stephen23
Stephen23 2020 年 10 月 8 日
編集済み: Stephen23 2020 年 10 月 8 日
@GreyHunter: processing multiple files is a very common task, the basic concepts are shown in the MATLAB documentation (note: no superfluous single quotes stuck onto the filenames):
Use the dir method, and of course inside the loop you can use whatever function/s you want to import those files, do whatever processing, and then export to some new files.
I strongly recommend that you keep your code in its own folder (e.g. the MATLAB folder in your Documents directory) and use absolute paths to specify the folders where the files are saved:
GreyHunter
GreyHunter 2020 年 10 月 8 日
thanks very much for your reply, I will give it a try without using the dir function as I am not allowed.

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 10 月 8 日
編集済み: Fangjun Jiang 2020 年 10 月 8 日
a='this include ''single quote'' and others.'
b="using 'string' is better"
  1 件のコメント
GreyHunter
GreyHunter 2020 年 10 月 8 日
thanks very much for your help.

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

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by