From: chinedu on
Ok so I have a project that I am working on and I am very new to matlab so I hve been doing a lot of trial and error. My project is to build a player that will take in a wav file "word+noise". I put in a db gain that I want to increase/decrease the noise by if the patient get the response correct or not. For the most port the project is done. I just have two problems:
1. how to I make my player play a list of wav files at radom thats in the listbox?
2. how do I make my pushbutton "repsonce" keep the new noise level so if I say the the patient got the response correct and the noise increase for the next file, that file will play at that noise level but have the voice untouced.
Here is my code so far


function varargout = threshold(varargin)
% THRESHOLD M-file for threshold.fig
% THRESHOLD, by itself, creates a new THRESHOLD or raises the existing
% singleton*.
%
% H = THRESHOLD returns the handle to a new THRESHOLD or the handle to
% the existing singleton*.
%
% THRESHOLD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in THRESHOLD.M with the given input arguments.
%
% THRESHOLD('Property','Value',...) creates a new THRESHOLD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to threshold_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help threshold

% Last Modified by GUIDE v2.5 09-Jul-2010 13:39:05

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @threshold_OpeningFcn, ...
'gui_OutputFcn', @threshold_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before threshold is made visible.
function threshold_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 threshold (see VARARGIN)

% Choose default command line output for threshold
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes threshold wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global data;

data.count=0;
data.genCount=1;
data.previous='A';


% --- Outputs from this function are returned to the command line.
function varargout = threshold_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1



% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end



% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data;

contents = get(handles.listbox1,'String');
pathname = contents{get(handles.listbox1,'Value')};
[data.y, data.Fs] = wavread(pathname);

(part I need help in)
[nrows,ncols]=size('pathname'); % get size of input matrix
cnt = 10*nrows; % enough times
while (cnt > 0)
pos1 = 1+fix(nrows.*rand); % get first random row
pos2 = 1+fix(nrows.*rand); % get second random row
tab=pathname
tmp = tab(pos1,:); % save first row
tab(pos1,:) = tab(pos2,:); % swap second into first
tab(pos2,:) = tmp; % move first into second
cnt=cnt-1;
end;

wavplay (data.y,data.Fs);



(2nd part I need help in)
s=data.y(:,1);
n=data.y(:,2);
if strcmp(data.previous, 'Yes')

n3=s+data.t*n;
data.y=[s, n3];



elseif strcmp(data.previous, 'No')
n3=s-data.t*n;
data.y=[s, n3];


% --- Executes on button press in pushbutton3. (opens the file to put into t he listbox)
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


[files path] = uigetfile('*.*','Please select a file', 'MultiSelect', 'on');

if ~path
return;
end

inputImages = get(handles.listbox1,'String');

if iscell(files) == 0
inputImages{length(inputImages)+1} = fullfile(path, files);
% inputImages{length(inputImages)+1} = files;
else
for n = 1:length(files)
inputImages{length(inputImages)+1} = fullfile(path, files{n});
% inputImages{length(inputImages)+1} = files{n};
end
end

set(handles.listbox1, 'String', inputImages);
%set(handles.listbox1, 'Value', 1);
guidata(hObject, handles);


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data;

prompt = {'Threshold size:'};
dlg_title = 'Input db size';
num_lines = 1;
def = {'','hsv'};
options.WindowStyle='default';
answer = inputdlg(prompt,dlg_title,num_lines,def);
data.d=str2num(answer{1});

function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double



% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data;
button=questdlg('IS THE RESPONSE CORRECT','','Yes','No','default')

s=data.y(:,1);
n=data.y(:,2);
assignin('base', 'n', n);
a=leq(s,length(s),.00002^2);
b=leq(n,length(n),.00002^2);
data.c(data.count+1)=a-b
data.d


if strcmp(button,'Yes')
if strcmp(data.previous, 'No')
data.count=data.count+1;
if data.count==14
th(data.genCount) = sum(data.c(4:14))/10;
msgbox(['14 reversals have been reached: threshold = ' num2str(th(data.genCount))]);
data.count = 0;
data.genCount=data.genCount+1;
if data.genCount==3
finalTh=sum(th)/3;
msgbox(['final thr: ' num2str(finalTh)]);
end
end
end
data.previous = 'Yes';

data.t=sqrt(10^((data.d)/20))
n2=data.t*n;
assignin('base', 'n2', n2);
size(s)
size(n2)
y2=[s, n2];
%wavplay(n2, data.Fs)
data.n=n2;
data.y=y2;
%


elseif strcmp(button, 'No')
if strcmp(data.previous, 'Yes')
data.count=data.count+1;
if data.count==14
th(data.genCount) = sum(data.c(4:14))/10;
msgbox(['14 reversals have been reached: threshold = ' num2str(th(data.genCount))]);
data.count = 0;
data.genCount=data.genCount+1;
if data.genCount==3
finalTh=sum(th)/3;
msgbox(['final thr: ' num2str(finalTh)]);
end
end
end
data.previous= 'No';

data.t=sqrt(10^(-(data.d)/20))
n2=data.t*n;
assignin('base', 'n2', n2);
y2=[s, n2];
%wavplay(y2, data.Fs)
data.n=n2;
data.y=y2;

end

function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

a = get(handles.listbox1,'string')
index = get(handles.listbox1,'Value')
a(index,:) = []
if isempty(a)
set(handles.listbox1,'String', {}, 'Value', [])
else
set(handles.listbox1,'string',a, 'Value', min(index,length(a)))
end
From: us on
"chinedu " <chinedu.okoro(a)nyumc.org> wrote in message <i1g1io$ndq$1(a)fred.mathworks.com>...
> Ok so I have a project that I am working on and I am very new to matlab so I hve been doing a lot of trial and error. My project is to build a player that will take in a wav file "word+noise". I put in a db gain that I want to increase/decrease the noise by if the patient get the response correct or not. For the most port the project is done. I just have two problems:
> 1. how to I make my player play a list of wav files at radom thats in the listbox?

a hint:

help randperm;

us
From: chinedu on
I tried that this is what i did:

r=randperm(length('contents'));
t1=pathname(r)
[data.y,data.Fs]=sort(r,'random');

but still does nothing. What i want to do is when I press play it picks any wav file and plays it. Any suggestions?
From: chinedu on
"So this is what I have done so far but still nothing.

contents = get(handles.listbox1,'String');
pathname = contents{get(handles.listbox1,'Value')};
m=length(pathname)
inds=randperm(m);
for q=1:m
sound=pathname(inds(q))name
[data.y, data.Fs] = wavread(pathname);
end

wavplay (data.y,data.Fs);

I keep getting this error

??? Improper index matrix reference.

Error in ==> untitled>pushbutton2_Callback at 132
sound=pathname(inds(q)).name

how can I fix this. This is due asap!!