MATLAB AppDesigner基本使用教程
作者:齊花Guyc(CAUC)
文章目錄
- MATLAB AppDesigner基本使用教程
- 一、創建項目
- 二、編寫回調函數
- 1. 按鈕——獲取選擇文件路徑
- 2. 按鈕——保存文件路徑
- 3. 單選按鈕組
- 4. 復選框
- 5. 文本框顯示
- 三、打包APP
一、創建項目
建立空文件夾——新建APP(或者直接在命令行直接輸入appdesigner)
可以選擇空白的APP直接進入
進入后,左側是組件庫,中間是畫布,右側是組件屬性。
中間模塊的右上角可以切換設計視圖與代碼視圖,代碼視圖可以進行APP具體邏輯功能的實現。
在此,先進行保存項目,以便日后的重復操作。
二、編寫回調函數
點擊設計視圖右側的代碼視圖,可以看到有三種類型的插入:回調、函數、屬性。
回調函數:當用戶與界面組件交互時會自動觸發的代碼塊。比如,用戶點擊“計算”按鈕,完成計算的操作。
函數:實現邏輯功能。
屬性:是APP的全局變量。
在此介紹常用組件的回調函數
1. 按鈕——獲取選擇文件路徑
function ButtonPushed(app, event) [file,path] = uigetfile('*.*');fullPath = fullfile(path, file);
end
2. 按鈕——保存文件路徑
function Button_Pushed(app, event)% 彈出目錄選擇對話框selectedPath = uigetdir;
end
3. 單選按鈕組
function ButtonGroupSelectionChanged(app, event)selectedButton = app.ButtonGroup.SelectedObject;if strcmp(selectedButton.Text, '1')elseif strcmp(selectedButton.Text, '2')end
end
4. 復選框
function CheckBox_ValueChanged(app, event)value = app.CheckBox.Value;if valueelseend
end
5. 文本框顯示
將文本區域設置為不可編輯
tryapp.OutputText(end+1) = sprintf(' XXXX ',values);app.OutputTextArea.Value = strjoin(app.OutputText, newline);app.OutputTextArea.scroll('bottom');
catch eapp.OutputText(end+1) = sprintf('錯誤: %s', e.message);app.OutputTextArea.Value = strjoin(app.OutputText, newline);app.OutputTextArea.scroll('bottom');
end
三、打包APP
選擇獨立桌面APP