Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Answers (1)

Wayne King
Wayne King on 31 Mar 2013
Edited: Wayne King on 31 Mar 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 Comment
MatlabFan
MatlabFan on 31 Mar 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.

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!