How do I run script in guide with the use of input arguments?

2 次查看(过去 30 天)
I am new to matlab and have modified the code for a gui with will allow me to loud, play, pause, and stop audio. These buttons work, and I have created an additional button called classify that will run the script genre_of.m that will basically classsify what type of music it is that the user uploads. However, I have been getting issues trying to run this script because I am trying to run it with other arguments like this: genre_of(mfcc_cells,musicfilename,10). -mfcc is a workspace variable that holds a list of audio files -musicfilename is simply the file name passed from the load callback function -and 10 is just a simple input value used for counting.
So what Im trying to ask is how do I get my code to run my .m file from my gui. My gui code for the load and classify button is listed below:
function load_Callback(hObject, eventdata, handles)
myGui=guidata(handles.figure1);
[filename,pathname] = uigetfile({'*.wav';'*mp3'},'Select File');
handles.pathname=pathname;
handles.filename=filename;
[x,fs] = audioread([pathname filename]);
myGui.freqSam=fs;
myGui.datasound=x;
myGui.player=audioplayer(myGui.datasound,myGui.freqSam);
myGui.flag=2;
set(handles.text3,'String',[pathname filename]);
guidata(handles.figure1,myGui)
function classify_Callback(hObject, eventdata, handles)
pathname = [];
filename = [];
if isfield(handles,'pathname') && isfield(handles,'filename')
pathname = handles.pathname;
filename = handles.filename;
end
musicfilename=FixedLineString(pathname,filename);
genre_of(mfcc_cells,musicfilename,10)
f=fopen('C:\Users\matthew\Documents\MATLAB\MUSIC CLASSIFICATION\classification.txt');
s=textscan(f,'%s ');
fclose(f);
set(handles.text4,'Strings',s);

回答(1 个)

Kevin Gleason
Kevin Gleason 2017-5-5
I looks like "genre_of" generates a file. I see two options for making it work, (1) is likely better than (2).
1. Make "genre_of.m" a function.
This may be very simple, you may only need to add the following line to the top of the script:
function genre_of(mfcc, musicfilename, counter)
Make sure the input artument names match up with the variables names you use in the script currently.
2. Add required script variables to the Callback's workspace before calling the script.
A script uses the variables in the current workspace, this means you could also do the following:
musicfilename=FixedLineString(pathname,filename);
mfcc = mfcc_cells;
counter = 10;
genre_of;
Just make sure the workspace has all the variables that will be used in the "genre_of" script.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by