Matlab在列表框中加载文件错误:输入了无关的参数

时间:2017-04-01 16:26:17

标签: matlab listbox

我是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

1 个答案:

答案 0 :(得分:0)

您的代码中存在一些错误:

    {li}

    load_Callback cllback

    • 在致电uigetfile时有一个错字:有问题的Multiset应为Multiselect
    • 测试if(cCheck==0)应为if(cCheck):如果用户按下Open按钮,则uigetfile会返回1
    playlist_Callback

    中的
    • {li} if(iscell(listStr))
      • 列表名称应为listStr,而不是playlistStr
      • 如果符合条件(即如果listStrcellarray),则必须将所选项目listStr(listVal))从cellarray转换为{{1}使用char函数的字符串,因为char输入未定义fprintf

修正上述错误,两个回调结果:

cell

希望这有帮助,

Qapla'