Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
MatlabFan
MatlabFan am 31 Mär. 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.

Antworten (1)

Wayne King
Wayne King am 31 Mär. 2013
Bearbeitet: Wayne King am 31 Mär. 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 Kommentar
MatlabFan
MatlabFan am 31 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by