2017-04-01 32 views
0

我是新來matlab,我想加載列表框中的多個文件。到目前爲止,我有這個代碼,但它顯示了我的這個錯誤: 輸入了多餘的參數,請檢查文檔。 這是我的代碼:Matlab加載列表框中的文件錯誤:輸入多餘的參數

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

[flnm, flpth,cCheck]=uigetfile({'*.mp3'},... 
          'File Select',... 
          'Multiset', 'on'); 
%fullpathname=strcat(pathname, filename); 
%text=audioread(fullpathname); 
%set(handles.path_song, 'String',fullpathname);%show full path name in the listbox 

assignin('base','flnm',flnm); 
assignin('base','flpth',flpth); 
assignin('base','cCheck',cCheck); 

%If the user did not press the cancell button 
if(cCheck==0) 
%Reset selection to first entry 
set(handles.playlist,'Value',1); 
%Show selected filenames 
set(handles.playlist,'String',flnm); 
end 
%LIST------------------------Display Files--------------------------------- 

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

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

listStr=get(hObject,'String'); 
listVal=get(hObject,'Value'); 

%Display Selected files 
if(iscell(listStr)) 
    fileName=playlistStr(listVal); 
    fprintf('Selected file:%s\n',fileName); 
else 
    fileName=listStr; 
    fprintf('Selected file:%s\n',fileName); 
end 

回答

0

有在你的代碼中的一些錯誤:

  • load_Callback cllback

      呼叫
    • uigetfile有一個錯字:推測Multiset應該是Multiselect

    • 測試if(cCheck==0)應該if(cCheck):如果用戶按下Open按鈕,uigetfile回報1
  • playlist_Callback

    • 在列表中的if(iscell(listStr))

      • 的名稱應該是listStr代替playlistStr
      • 如果條件離子被滿足(即如果listStrcellarray),你必須使用char功能所選擇的項目(listStr(listVal))從cellarray轉換爲char字符串,因爲fprintf不是爲cell輸入
定義

修復上面的錯誤,這兩個回調的結果:

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

% [flnm, flpth,cCheck]=uigetfile({'*.txt'},... 
%        'File Select',... 
%        'Multiset', 'on'); 
[flnm, flpth,cCheck]=uigetfile({'*.txt'},... 
          'File Select',... 
          'Multiselect', 'on'); 
%fullpathname=strcat(pathname, filename); 
%text=audioread(fullpathname); 
%set(handles.path_song, 'String',fullpathname);%show full path name in the listbox 

assignin('base','flnm',flnm); 
assignin('base','flpth',flpth); 
assignin('base','cCheck',cCheck); 

%If the user did not press the cancell button 
%If the user did not press the cancell button 
% if(cCheck==0) 
if(cCheck) 
    %Reset selection to first entry 
    set(handles.playlist,'Value',1); 
    %Show selected filenames 
    set(handles.playlist,'String',flnm); 
end 

%LIST------------------------Display Files--------------------------------- 

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

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

listStr=get(hObject,'String'); 
listVal=get(hObject,'Value'); 

%Display Selected files 
if(iscell(listStr)) 
% % % fileName=playlistStr(listVal); 
    fileName=char(listStr(listVal)); 
    fprintf('Selected file:%s\n',fileName); 
else 
    fileName=listStr; 
    fprintf('Selected file:%s\n',fileName); 
end 

希望這有助於

Qapla'

相關問題