我想在MATLAB中实现GUI环境。我想使用“浏览器”按钮加载文件,然后将文件输入到要使用的代码中并输出。帮助。
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(~, ~, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname = strcat(pathname, filename);
text = fileread(fullpathname);
set(handles.text2, 'String', fullpathname)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname = strcat(pathname, filename);
text = fileread(fullpathname);
set(handles.text3, 'String', fullpathname)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(~, ~, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.txt'},'File Selector');
fullpathname = strcat(pathname, filename);
text = fileread(fullpathname);
set(handles.text4, 'String', fullpathname)
D1=load('text2');
D1=D1';
D1=reshape(D1,l1*l2,1);
%% D2,D3 매트릭스 direct데이터 파일
D2=load('text3');
D3=load('text4');
答案 0 :(得分:0)
您使用
set(handles.text2, 'String', fullpathname)
因此在需要名称的例程中,可以使用
get(handles.text2, 'String')
答案 1 :(得分:0)
您的所有三个回调已经完全完成了您想做的事情:
fullpathname
变量中String
,text2
或text3
的{{1}}属性。因此,现在有几种原因可能会导致您无法按预期进行:
text4
,text2
或text3
不存在。因此Matlab不知道在哪里分配文本。您可以使用上方菜单中的“对象”浏览器来获得所有元素的概述:text4
无法读取文件的内容。您可以通过使用简单的非GUI脚本确保fileread
正在处理文件来进行检查。