[英]How do I get the path from MATLAB?
我想在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');
你用過
set(handles.text2, 'String', fullpathname)
因此在需要名稱的例程中,您可以使用
get(handles.text2, 'String')
您的所有三個回調已經完全完成了您想做的事情:
fullpathname
變量中 text2
, text3
或text4
的String
屬性。 因此,現在有幾個原因導致此操作無法按預期工作的原因:
text2
, text3
或text4
存在。 因此Matlab不知道在哪里分配文本。 您可以使用上方菜單中的“對象”瀏覽器來獲得所有元素的概述: fileread
無法讀取文件的內容。 您可以通過使用簡單的非GUI腳本確保fileread
在文件上正常工作來進行檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.