how to add single quotes ' ' in a string?

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

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 8 Oct 2020
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 commentaires

GreyHunter
GreyHunter le 8 Oct 2020
tahnks very mcuh for your answer, it worked.
Ameer Hamza
Ameer Hamza le 8 Oct 2020
I am glad to be of help!
GreyHunter
GreyHunter le 8 Oct 2020
Modifié(e) : GreyHunter le 8 Oct 2020
@Ameer Hamza I 've got now a very weird error message:
Error using audioread (line 105)
Expected input to be a non-missing string scalar or character vector.
Error in general_Test (line 64)
x=audioread(signal_data);
do you have any idea why it gives me that?
I am trying this:
signal_data=strcat('''',Data,'.wav''');
x=audioread(signal_data);
Stephen23
Stephen23 le 8 Oct 2020
"do you have any idea why it gives me that?"
Quite possibly because of the superfluous single quotes that you stuck on both ends of that character vector.
Remove them, even if they are not the cause of this bug, they are a bug that will stop your code from working.
Hi @Steve when I remove them I got the same error:
signal_data=strcat(Data,'.wav');
x=audioread(signal_data);
signal is equal to this: signal.wav
and for audioread function, i think it needs something like this: audioread('signal.wav') ;in order to go read that audio signal.
Stephen23
Stephen23 le 8 Oct 2020
Modifié(e) : Stephen23 le 8 Oct 2020
"Hi @Steve when I remove them I got the same error:"
I don't know who "Steve" is.
So that error is unrelated to the single quotes. You should actually be asking about that error:
"signal is equal to this: signal.wav and for audioread function, i think it needs something like this: audioread('signal.wav') ;in order to go read that audio signal."
Nope, it is not required to stick superflous single quotes onto filenames. That would be a complete pain.
You are confusing the syntax for defining a character vector (i.e. using single quotes) with the content of that character vector (which can certainly include single quotes if required, but filenames certainly do NOT need).
GreyHunter
GreyHunter le 8 Oct 2020
I will try to explain more. so, I am a able to read a text file which has names in it. For example, John, Jim,Alex and etc. every signle name has a folder in the Matlab location which has all the names which are included in the text file but they are wav. So, every single wav file has a record of thier voice from different people ( John, Alex and etc). if I will go on the command line and type x=audioread('john.wav') it will read the audio from the folder. So I was thinking to extract all the name and with a loop every time to read a name from the text file to read also the wav in order then to filter it and save it in a differrent location.
GreyHunter, When you call the audioread() functions, you don't need a separate apostrophe symbol. The following two are equivalent
x=audioread('john.wav')
and
name = 'john.wav';
x=audioread(name)
Stephen23
Stephen23 le 8 Oct 2020
Modifié(e) : Stephen23 le 8 Oct 2020
@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 le 8 Oct 2020
thanks very much for your reply, I will give it a try without using the dir function as I am not allowed.

Connectez-vous pour commenter.

Plus de réponses (1)

Fangjun Jiang
Fangjun Jiang le 8 Oct 2020
Modifié(e) : Fangjun Jiang le 8 Oct 2020
a='this include ''single quote'' and others.'
b="using 'string' is better"

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by