Problem loading .wav files in matlab from directory

  • Thread starter Thread starter Jamshaid3
  • Start date Start date
  • Tags Tags
    files Matlab
Click For Summary

Discussion Overview

The discussion revolves around issues related to loading .wav files in MATLAB from a specified directory. Participants are seeking assistance with code functionality and error handling, particularly in the context of MATLAB version R2009a.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes an error encountered when attempting to load .wav files using a custom function, indicating that the function fails to open the specified files.
  • Another participant suggests that the issue may be related to the version of MATLAB being used and provides links to MATLAB documentation and external resources for reading .wav files.
  • A participant expresses frustration with the inability to load multiple .wav files and requests specific code examples to achieve this.
  • There is a suggestion to verify the current directory in MATLAB to ensure that the .wav files are located where MATLAB expects them to be.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the error or the best solution, as multiple approaches and suggestions are presented without resolution.

Contextual Notes

There is uncertainty regarding the compatibility of the provided code with different versions of MATLAB, and the discussion includes references to external resources that may or may not address the specific issue at hand.

Jamshaid3
Messages
2
Reaction score
0
Hello participants. Can anyone help me in the code of loading wavs... I am getting some error...
Function for the Code is...


function [wavs,fs] = load_wavs(directory)

% Initialize variables
data = 0;
fs = 0;

% Load the wavs
if(nargin < 1),
D = dir;
else
D = dir(directory);
end
for i=2 : size(D,1),
if(size(findstr(D(i).name,'.wav'),1))
[wav,fs,nbits] = wavread(D(i).name);
wav = wav ( :,1 );
data = add_wav(wav,data);
end
end
wavs = zeros(size(data,2)-1,size(data,1));
for i=2 : size(data,2),
wavs( i-1,: ) = data ( :,i )';
end

After saving it when I call it from command window ...

x = load_wavs('test') %test is a folder containing .wav files in my current directory

It gives me error...

? Error using ==> wavread at 67
Cannot open file.

Error in ==> load_wavs at 26
[wav,fs,nbits] = wavread(D(i).name);

Am I doing something wrong... I have tried to change the path but same result...
Please help me to get rid of this inconvenience... ASAP
 
Physics news on Phys.org
Welcome to PF!

It helps a lot if you bracket your MATLAB code with [ code] tags. It will preserve the indentation and spacing
of the source and offset it from the rest of your post.

With respect to the .wav file, it may depend on the version of MATLAB you have but here's for the latest version:

http://www.mathworks.com/help/matlab/ref/wavread.html

and here's some discussion on reading a wav file from the current directory:

http://stackoverflow.com/questions/6319870/how-to-read-a-wav-file-into-matlab[/code]
 
Last edited by a moderator:
I am using MATLAB R2009a. I have tried many ways but all in vane... Could you please write down some code to load multiple .wav files from a directory...
 
Jamshaid3 said:
I am using MATLAB R2009a. I have tried many ways but all in vane... Could you please write down some code to load multiple .wav files from a directory...

Did you read the references in my post? I'm not near a MATLAB implementation and I haven't had a need to work with wav files. The references look pretty good. You can compare your code to what you see and maybe you'll find what is wrong.

Can find a function that will tell you what MATLAB thinks is the current directory?

And print the current directory path.

It may be that your files are not in the directory that MATLAB is looking at.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
12K
  • · Replies 15 ·
Replies
15
Views
7K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K