필터 지우기
필터 지우기

listbox selection, push button and which error..

조회 수: 1 (최근 30일)
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 20일
댓글: 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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by