我是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 :(得分:0)
您的代码中存在一些错误:
在load_Callback
cllback
uigetfile
时有一个错字:有问题的Multiset
应为Multiselect
if(cCheck==0)
应为if(cCheck)
:如果用户按下Open
按钮,则uigetfile
会返回1
playlist_Callback
中的
if(iscell(listStr))
listStr
,而不是playlistStr
listStr
是cellarray
),则必须将所选项目listStr(listVal)
)从cellarray
转换为{{1}使用char
函数的字符串,因为char
输入未定义fprintf
修正上述错误,两个回调结果:
cell
希望这有帮助,
Qapla'