練習使用Matlab的對話框,並與有的沒的指令結合順便紀錄用法。 展示圖 程式碼 clc; clear; % 取得圖片所在的目錄 images_dir = uigetdir('.','Choose a directory for images'); if images_dir == 0, return; end % 檢查目錄存在否 chk_code = exist(images_dir,'dir'); if chk_code ~= 7 msg = sprintf('''%s''not exit or not a directory\n', in_dir); errordlg(msg, 'Are you sure?'); return; end % 搜尋檔案並統計 file_list = dir(fullfile(images_dir, '*.jpg')); file_list_num = size(file_list); if file_list_num(1) <= 0 msg = sprintf('Can not find any JPEG image in this directory.\n'); msgbox(msg, 'Are you kidding?'); return; end msg = sprintf('Total JPEG image number:%d\n', file_list_num(1)); uiwait(msgbox(msg, 'Scanning images finished')); % 列出檔案名稱給使用者選擇 file_list_names = {file_list.name}; pushbtn = 1; while pushbtn == 1 [selindx,pushbtn] = listdlg('SelectionMode', 'single',... 'PromptString', 'Select image to show...