listbox selection, push button and which error..

2 ビュー (過去 30 日間)
Edmund Paul Malinowski
Edmund Paul Malinowski 2015 年 11 月 20 日
Hey all,
I have a gui listbox that loads only wav file names into it on the gui opening. From there a push button takes the selection and audioreads the chosen file. Well it should do but with the following code, it errors out. See error below below..
% **********************************************
% FORM LOAD AND OPEN..
% **********************************************
% --- Executes just before EPM_gui_form is made visible.
function EPM_gui_form_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for EPM_gui_form
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% DECLARE GLOBAL VARIABLES..
%global isMELODY; % DEFINE isMELODY AS CATCH FOR IF MELODY IS CREATED OR NOT..
%isMELODY = 0; % SET isMELODY TO 0 (NOT CREATED YET)..
global NoteX; % DECLARE VARIABLE FOR NOTE LETTER..
global FreqX; % DECLARE VARIABLE FOR NOTE FREQUENCY..
global FreqBPFTStop1; % DECLARE VARIABLE FOR BP FILTER STOPBAND 1..
global FreqBPFTPass1; % DECLARE VARIABLE FOR BP FILTER PASSBAND 1..
global FreqBPFTPass2; % DECLARE VARIABLE FOR BP FILTER PASSBAND 2..
global FreqBPFTStop2; % DECLARE VARIABLE FOR BP FILTER STOPBAND 2..
global FreqBSFTStop1; % DECLARE VARIABLE FOR BS FILTER STOPBAND 1..
global FreqBSFTPass1; % DECLARE VARIABLE FOR BS FILTER PASSBAND 1..
global FreqBSFTPass2; % DECLARE VARIABLE FOR BS FILTER PASSBAND 2..
global FreqBSFTStop2; % DECLARE VARIABLE FOR BS FILTER STOPBAND 2..
global d; % DECLARE VARIABLE FOR DIRECTORY..
global strLOAD; % DECLARE VARIABLE FOR FILENAMES..
% LOAD WAV FILES INTO LISTBOX..
d = dir('*.wav'); % Select Only ‘.wav’ Files
strLOAD = {d.name};
set(handles.listFILEwav,'String',strLOAD); %set string
% **********************************************
% **********************************************
% FORM OUTPUT..
% **********************************************
% --- Outputs from this function are returned to the command line.
function varargout = EPM_gui_form_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% **********************************************
% **********************************************
% LOAD WAV..
% **********************************************
% --- Executes on button press in btLOAD.
function btLOAD_Callback(hObject, eventdata, handles)
global strLOAD; % DECLARE VARIABLE FOR FILENAMES..
wav_name = strLOAD; % FILE NAME OF THE SELECTED PATH..
wav_path = which(wav_name); % PATH OF THE SELECTED FILE..
msgbox({'Wav: ',wav_name});
% OPEN AND READ THE DESIRED AUDIO WAV FILE..
[Wave,Fs] = audioread(wav_name);
soundsc(Wave, Fs);
% **********************************************
Here's the error:
Error using which
Argument must contain a string.
Error in EPM_gui_form>btLOAD_Callback (line 89)
wav_path = which(wav_name); % Path Of Selected File
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in EPM_gui_form (line 34)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)EPM_gui_form('btLOAD_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
It says which needs to be a string but I would have thought that the dir kicks out a string of the files and populating the listbox with these strings as strLOAD, so therefore the code in the btLOAD_Callback should be a string? Or am i missing something?
Thanks.
Paul..

採用された回答

Walter Roberson
Walter Roberson 2015 年 11 月 20 日
You are incorrect. The pushbutton ignores the listbox rather than taking the selection. Instead the pushbutton is taking the result of
d = dir('*.wav'); % Select Only ‘.wav’ Files
strLOAD = {d.name};
which is creating strLOAD as a cell array of strings rather than as a single string. You cannot which() a cell array of strings.
Using which() is a waste of time. You already know which directory they are in: they are in the directory that you did the dir('*.wav') inside. You can find out which directory you are in by using the call cd()
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 11 月 20 日
strLIST{valLIST}
Edmund Paul Malinowski
Edmund Paul Malinowski 2015 年 11 月 20 日
That got it :) thanks Walter

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by