簡體   English   中英

如何從MATLAB獲取路徑?

[英]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')

您的所有三個回調已經完全完成了您想做的事情:

  1. 當用戶按下分配了回調之一的按鈕時,他們將打開文件瀏覽器,用戶可以在其中選擇文件。
  2. 他們將路徑保存在fullpathname變量中
  3. 他們將文本分配給句柄text2text3text4String屬性。

因此,現在有幾個原因導致此操作無法按預期工作的原因:

  • 您的回調函數均未分配給GUI的用戶界面元素。 如果您在Matlab GUIDE功能中打開GUI,只需右鍵單擊其中一個按鈕並檢查屬性檢查器,就​​可以簡單地進行檢查。 應該有一個看起來像這樣的條目:

物業檢查員的外觀

  • 句柄text2text3text4存在。 因此Matlab不知道在哪里分配文本。 您可以使用上方菜單中的“對象”瀏覽器來獲得所有元素的概述:

對象瀏覽器

  • fileread無法讀取文件的內容。 您可以通過使用簡單的非GUI腳本確保fileread在文件上正常工作來進行檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM