Error using a variable as input for audioread()

Hello.
I'm trying to load a .wav file, based on user input. For testing, I am using sample.wav. When I type audioread('sample.wav'), it works perfectly, but when I type:
fileName1 = inputdlg('Type the filename of the .wav file you would like to upload');
% A dialogue box pops up and I type sample.wav into it
audioread(fileName1);
This results in the following error:
Error using which
Argument must contain a string.
Error in audiovideo.internal.absolutePathForReading (line 7)
whichFileName = which(filename);
Error in audioread (line 74)
filename = audiovideo.internal.absolutePathForReading(...
What am I doing wrong?

4 件のコメント

Tiba Abdulhameed
Tiba Abdulhameed 2016 年 3 月 3 日
the problem is your file name is stored in cell type of data. you should change it to string before using audioread. you can try audioread(fileName1{1});
Tiba Abdulhameed
Tiba Abdulhameed 2016 年 3 月 3 日
% %In addition, you can make the user select from existing files by ;
[file,path] = uigetfile({'*.wav';},'input file');
name=fullfile(path,file)
[Z, fs] =audioread(name)
Saad Rehman
Saad Rehman 2020 年 4 月 17 日
Undefined variable "audiovideo" or class "audiovideo.internal.absolutePathForReading".
Error in audioread (line 74)
filename = audiovideo.internal.absolutePathForReading(...
I've an error. kindly guide me how can I solve it?
Geoff Hayes
Geoff Hayes 2020 年 4 月 17 日
Saad - what is the line of code that you have written to load your audio file? Are you using audioread?

サインインしてコメントする。

回答 (1 件)

Harsha KVK
Harsha KVK 2022 年 7 月 28 日

0 投票

As input() takes only integers. Convert the file name to string.
fileName = string(input('Type the filename of the .wav file you would like to upload')); audioread(fileName);

質問済み:

2015 年 3 月 11 日

回答済み:

2022 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by