Demo: Matlab Management File and Menu Editor, Toolbar Editor
Demo: Matlab Management File and Menu Editor, Toolbar Editor
Page 1
Basic Matlab
% --- Executes just before Explorer is made visible. function Explorer_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Explorer (see VARARGIN) % Choose default command line output for Explorer handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes Explorer wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = Explorer_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on selection change in lstdrive. function lstdrive_Callback(hObject, eventdata, handles) % hObject handle to lstdrive (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns lstdrive contents as cell array % contents{get(hObject,'Value')} returns selected item from lstdrive try global pathname; global filename; global listfiles; global filesadd; indexlist = get(handles.lstdrive, 'Value'); temp = listfiles{indexlist}; filesadd = strcat(pathname, temp); if isdir(filesadd) pathname = strcat(filesadd,'\'); listfiles = refresh(pathname, filename);
Page 2
Basic Matlab
set(handles.lstdrive, 'string', listfiles); set(handles.txtBrowse, 'String', pathname); else axes(handles.axes1); set(handles.axes1, 'NextPlot', 'replace'); imshow(filesadd); set(handles.txtBrowse, 'String', filesadd); end catch end % --- Executes during object creation, after setting all properties. function lstdrive_CreateFcn(hObject, eventdata, handles) % hObject handle to lstdrive (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
% --- Executes during object creation, after setting all properties. function listbox2_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in btnPrev. function btnPrev_Callback(hObject, eventdata, handles) % hObject handle to btnPrev (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try global pathname; global listfiles; status = 1; indexlist = get(handles.lstdrive, 'Value'); [filesadd, inc] = DynamicImage(pathname, status, indexlist, listfiles); set(handles.lstdrive, 'Value', inc); set(handles.txtBrowse, 'String', filesadd);
Page 3
Basic Matlab
imshow(filesadd); catch end % --- Executes on button press in btnNext. function btnNext_Callback(hObject, eventdata, handles) % hObject handle to btnNext (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try global pathname; global listfiles; status = 0; indexlist = get(handles.lstdrive, 'Value'); [filesadd, inc] = DynamicImage(pathname, status, indexlist, listfiles); set(handles.lstdrive, 'Value', inc); set(handles.txtBrowse, 'String', filesadd); imshow(filesadd); catch end function [filesadd, inc] = DynamicImage(pathname, status, indexlist, listfiles) switch status case 0 inc = indexlist + 1; if inc > length(listfiles) inc = 3; end case 1 inc = indexlist - 1; if inc < 3 inc = length(listfiles); end end temp = listfiles{inc}; filesadd = strcat(pathname, temp);
% --- Executes on button press in btnDel. function btnDel_Callback(hObject, eventdata, handles) % hObject handle to btnDel (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try warning off; global filesadd; global pathname; global filename;
Page 4
Basic Matlab
pilih = questdlg('Are You Sure Want To Delete This File?', ... 'Information Delete', 'Okay dude', 'No dude', 'No dude'); switch pilih case 'Okay dude' delete(filesadd); end listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles); catch end % --- Executes during object creation, after setting all properties. function txtBrowse_CreateFcn(hObject, eventdata, handles) % hObject handle to txtBrowse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in btnBrowse. function btnBrowse_Callback(hObject, eventdata, handles) % hObject handle to btnBrowse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try global filename; global pathname; global listfiles; [filename, pathname] = uigetfile('*.*', 'Pilih File'); if ~isequal(filename,0) || ~isequal(pathname,0) set(handles.lstdrive, 'Enable', 'on'); set(handles.txtBrowse, 'String', pathname); listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles); end catch end % This function to list all files name in current directory function listfiles = refresh(pathname, filename) try files = dir(strcat(pathname,'*.*')); m = 1;
Page 5
Basic Matlab
n = 1; for k = 1:numel(files) if isdir(strcat(pathname,files(k).name)) listfiles1{m} = files(k).name; m = m + 1; else listfiles2{n} = files(k).name; n = n + 1; end end if length(listfiles2) < 2 listfiles = listfiles1; else listfiles = [listfiles1 listfiles2]; end catch end % --- Executes during object creation, after setting all properties. function btnBrowse_CreateFcn(hObject, eventdata, handles) % hObject handle to btnBrowse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties. function btnRename_CreateFcn(hObject, eventdata, handles) % hObject handle to btnRename (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties. function btnNext_CreateFcn(hObject, eventdata, handles) % hObject handle to btnNext (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties. function btnPrev_CreateFcn(hObject, eventdata, handles) % hObject handle to btnPrev (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO)
Page 6
Basic Matlab
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try global pathname; global listfiles; global filename; uurl = get(handles.txtBrowse, 'String'); [bar, kol] = find(uurl == char(92)); if isdir(uurl) if kol(end) == length(uurl) uurl = uurl(1:length(uurl)-(kol(end)-kol(end-1))); else uurl = uurl(1:length(uurl)-(length(uurl)-kol(end))); end else uurl = uurl(1:kol(end-1)); end set(handles.txtBrowse, 'String', uurl); pathname = uurl; listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles); catch end
% --- Executes on key press with focus on lstdrive and none of its controls. function lstdrive_KeyPressFcn(hObject, eventdata, handles) % hObject handle to lstdrive (see GCBO) % eventdata structure with the following fields (see UICONTROL) % Key: name of the key that was pressed, in lower case % Character: character interpretation of the key(s) that was pressed % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed % handles structure with handles and user data (see GUIDATA) try global pathname; global listfiles; global filesadd; indexlist = get(handles.lstdrive, 'Value'); temp = listfiles{indexlist}; filesadd = strcat(pathname, temp); imshow(filesadd); set(handles.txtBrowse, 'String', filesadd); catch end
Page 7
Basic Matlab
% --- Otherwise, executes on mouse press in 5 pixel border or over lstdrive. function lstdrive_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to lstdrive (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try global pathname; global listfiles; global filesadd; indexlist = get(handles.lstdrive, 'Value'); temp = listfiles{indexlist}; filesadd = strcat(pathname, temp); imshow(filesadd); set(handles.txtBrowse, 'String', filesadd); catch end
% -------------------------------------------------------------------function mnuClose_Callback(hObject, eventdata, handles) % hObject handle to mnuClose (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all;
% -------------------------------------------------------------------function mnuAbout_Callback(hObject, eventdata, handles) % hObject handle to mnuAbout (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('This is only a demo on how to use File Management Toolbox in Matlab');
% -------------------------------------------------------------------function mnuCreator_Callback(hObject, eventdata, handles) % hObject handle to mnuCreator (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('Design and Program by Jans Hendry'); % -------------------------------------------------------------------function ctxCopyFile_Callback(hObject, eventdata, handles) % hObject handle to ctxCopyFile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global filesadd; global TempCopy; global ctxstatus;
Page 8
Basic Matlab
% -------------------------------------------------------------------function ctxMoveTo_Callback(hObject, eventdata, handles) % hObject handle to ctxMoveTo (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global filesadd; global TempCopy; global ctxstatus; if ~isdir(filesadd) TempCopy = filesadd; ctxstatus = 1; end
% -------------------------------------------------------------------function Addition_Callback(hObject, eventdata, handles) % hObject handle to Addition (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------function mnuNewFold_Callback(hObject, eventdata, handles) % hObject handle to mnuNewFold (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global pathname; global filename; NewFolder = inputdlg('Write New Folder Name','New Folder',1); mkdir(pathname,NewFolder{1}); listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles);
function txtBrowse_Callback(hObject, eventdata, handles) % hObject handle to txtBrowse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of txtBrowse as text % str2double(get(hObject,'String')) returns contents of txtBrowse as a double
Page 9
Basic Matlab
try global filename; global pathname; global listfiles; [filename, pathname] = uigetfile('*.*', 'Pilih File'); if ~isequal(filename,0) || ~isequal(pathname,0) set(handles.lstdrive, 'Enable', 'on'); set(handles.txtBrowse, 'String', pathname); listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles); end catch end
% -------------------------------------------------------------------function mnuPasteFile_Callback(hObject, eventdata, handles) % hObject handle to mnuPasteFile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try global TempCopy; global pathname; global ctxstatus; global filename; pathname = PPaste(ctxstatus, pathname, TempCopy); listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles); catch end function pathname = PPaste(ctxstatus, pathname, TempCopy) try switch ctxstatus case 0 TempPaste = pathname; copyfile(TempCopy, TempPaste,'f'); pathname = TempPaste; case 1 TempPaste = pathname; movefile(TempCopy, TempPaste,'f'); pathname = TempPaste; end catch end
% --------------------------------------------------------------------
Page 10
Basic Matlab
function ctxRemove_Callback(hObject, eventdata, handles) % hObject handle to ctxRemove (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global filesadd; global pathname; global filename; ans1 = 'Yes, Dude'; ans2 = 'No, Dude'; title = 'Warning'; if isdir(filesadd) quest = 'Are You sure want to delete this folder and content(s) ?'; decide = questdlg(quest,title,ans1,ans2,ans2); switch decide case 'Yes, Dude' rmdir(filesadd,'s') end else msgbox('This is not a folder, choose a folder!!'); end listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles);
% -------------------------------------------------------------------function ctxDelete_Callback(hObject, eventdata, handles) % hObject handle to ctxDelete (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) try warning off; global filesadd; global pathname; global filename; pilih = questdlg('Are You Sure Want To Delete This File?', ... 'Information Delete', 'Okay dude', 'No dude', 'No dude'); switch pilih case 'Okay dude' delete(filesadd); end listfiles = refresh(pathname, filename); set(handles.lstdrive, 'string', listfiles); catch end
% --------------------------------------------------------------------
Page 11
Basic Matlab
function mnuFile_Callback(hObject, eventdata, handles) % hObject handle to mnuFile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------function ctxHorisonFlip_Callback(hObject, eventdata, handles) % hObject handle to ctxHorisonFlip (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global filesadd; fliplr(filesadd); RESULT
Page 12
Basic Matlab
I will make the tutorial about how to use MATLAB MENU EDITOR and MATLAB TOOLBAR EDITOR later. Also how to combine them with matlab files management toolbar. This work is simple yet valuable. Full of tricky in programming. @ thanks
Page 13