Hi there! I am new to Matlab and gui especially, please help me! I need to play wav files one by one by pushing a button in gui. My files are in a folder, but I need to play them in a random way. I did permutations to shuffle them (this is because I need to know how exactly they shuffled, to make a statistics). In my opening function I wrote:
% --- Executes just before MYGUI is made visible.
function MYGUI_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to MYGUI (see VARARGIN)
% Choose default command line output for MYGUI
handles.output = hObject;handles.status=0;%inizialize global variable
global rFoldData = dir('New Folder'); %Put metadata for folder in variable
FoldIndex = [FoldData.isdir]; %Gets list of files in folder
FileList = {FoldData(~FoldIndex).name}; FileList = FileList'; %Transpose resultant row vector into column vector
v = FileList';P = perms(v); %make permutation of verctor v
r = P(9,:) %select 10th row (random choice)
r = 'comb3.wav' 'comb2.wav' 'comb4.wav' 'comb1.wav'
In my pushbutton callback (PLAYAUDIObutton) I have:
% --- Executes on button press in PLAYAUDIObutton.
function PLAYAUDIObutton_Callback(hObject, eventdata, handles)% hObject handle to PLAYAUDIObutton(see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global rif handles.status==0 handles.status=1; k = r{1, 1}; %select 1st wav file from 10th row
[y,Fs]=wavread(k); %Import and play file
handles.audio = audioplayer(y,Fs); play(handles.audio);else msgbox ('Test is finished. Thank you for your participation!');endguidata(hObject,handles);
But, this code is only for playing the very first audio file from my list (comb3.wav). Now I need to figure out how to play all 4 files one by one by pushing PLAYAUDIOpushbutton: I need to press button and hear comb3.wav, by pushing the same button second time to hear comb2.wav and etc. What function should I choose to play them sequentially? There could be not only 4 files, but around 20… Thank you in advance!!
Best Answer