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

4 views (last 30 days)
Matt Ball
Matt Ball on 1 May 2017
Answered: Kevin Gleason on 5 May 2017
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)
[filename,pathname] = uigetfile({'*.wav';'*mp3'},'Select File');
[x,fs] = audioread([pathname filename]);
set(handles.text3,'String',[pathname filename]);
function classify_Callback(hObject, eventdata, handles)
pathname = [];
filename = [];
if isfield(handles,'pathname') && isfield(handles,'filename')
pathname = handles.pathname;
filename = handles.filename;
f=fopen('C:\Users\matthew\Documents\MATLAB\MUSIC CLASSIFICATION\classification.txt');
s=textscan(f,'%s ');

Answers (1)

Kevin Gleason
Kevin Gleason on 5 May 2017
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:
mfcc = mfcc_cells;
counter = 10;
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!