Borrar filtros
Borrar filtros

How to open a .wav file from matlab using a string name?

1 visualización (últimos 30 días)
MatlabFan
MatlabFan el 31 de Mzo. de 2013
Hi,
... and thanks for helping.
I want to open a .wav file in matlab just from a string name. I don't know what the string name will be until I run the program. I do know that whatever the string name will be, it will exist in the current folder.I have tried multiple approaches unsuccessfully. below is the latest that I have produced
if true
list=get(handles.targetSelection_popupmenu,'String');
val=get(handles.targetSelection_popupmenu,'Value');
str=list{val};
filename=[sr,'.wav'];
[VoiceTrgt fsTrgt]=wavread(filename,'.wav');
end
It does not work. so, as you can guess, str can be, say, Symphony11 or Symphony12 or whatever... I want to read the Symphony.
Thanks.

Respuestas (1)

Wayne King
Wayne King el 31 de Mzo. de 2013
Editada: Wayne King el 31 de Mzo. de 2013
Can you say what error you are getting? I'm not sure why you have the following
filename=[sr,'.wav'];
[VoiceTrgt fsTrgt]=wavread(filename,'.wav');
Why are you calling wavread with an '.wav' input argument? There is no such input argument. The above is probably giving you an "unrecognized data format" error because it expects a string like 'double' or 'native'
Just do the following
filename = [sr, '.wav'];
[VoiceTrgt fsTrgt]=wavread(filename);
Assuming that filename ends up as something like symphony11.wav.
By the way, the recommend functionality to use is audioread() assuming you have a version of MATLAB that contains that function.
  1 comentario
MatlabFan
MatlabFan el 31 de Mzo. de 2013
First of all Wayne, Thank you for assisting me. I realized that I had two mistakes in my code: instead of sr it should have been str (see code above. Also, as you pointed out, I should not have called the wavread with a '.wav' input argument the way I did it in the code above. Thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by