Plot a sound file in MATLAB GUI

3 visualizaciones (últimos 30 días)
Emre Akinci
Emre Akinci el 7 de Jun. de 2019
Comentada: Emre Akinci el 9 de Jun. de 2019
Hello everyone I'm the best rookie in MATLAB and I need help again.
So I want to plot selected item on listbox1
thats my codes
function listbox1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
time= 1:5;
axess = get(handles, 'String');
signal = get(handles, 'Value');
axessignal = axess{signal};
plot(axessignal,time);
it will plot when user select an item on listbox1
I mean when user selects first item on listbox1 then axes1 will plot first item and user selects second item axes1 will plot it
all files are sound
by the way I'm getting this error when i try codes that i wrote up
Error using get
Conversion to double from struct is not
possible.

Respuesta aceptada

Emre Akinci
Emre Akinci el 7 de Jun. de 2019
code that you wrote shows me my listbox items
and when i examined hObjects it showed me properties of listbox1 string is selected file name
  3 comentarios
Walter Roberson
Walter Roberson el 9 de Jun. de 2019
Why do you assume 44100 when it is trivial to get the sampling frequency from the file?
You should avoid assuming that the files are in the current directory: you should be giving the user a choice of directories and you should record that choice. That is what the audiodir = handles.DirectoryOfAudioFiles; in my response was about.
Emre Akinci
Emre Akinci el 9 de Jun. de 2019
you are right sir.
but it is not very important because we are providing useable audiofiles
all files fs are 44100 and in 100000x1 dimension

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 7 de Jun. de 2019
function listbox1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
time= 1:5;
axess = get(hObject, 'String');
signal = get(hObject, 'Value');
signal_name = axess{signal};
Now you have to load the data whose name is given by signal_name, and then plot it. For example,
audiodir = handles.DirectoryOfAudioFiles;
filename = fullfile(audiodir, [signal_name, '.wav']);
[data, FS] = audioread(filename);
time = (0:size(data,1)-1)/FS;
plot(time, data(:,1));
  6 comentarios
Walter Roberson
Walter Roberson el 7 de Jun. de 2019
When you examined hObject, what showed up? The other information you provided suggests that you did see a UIControl but it is best to be sure.
When you are stopped at the error, what shows up if you try
axess = hObject.String
Walter Roberson
Walter Roberson el 8 de Jun. de 2019
axess = hObject.String;
signal = hObject.Value;

Iniciar sesión para comentar.

Categorías

Más información sobre Measurements and Spatial Audio en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by