How can i create a standard matlab template for new programs
조회 수: 42(최근 30일)
I like to have the same layout of my code every time i create a new program, at the moment i just copy and paste an .m file. But is there any way it start with the following comments and code each time i make a new file matlab file ?
% Author: Thor P. Nielsen
% Date: XX-XX-20XX
% Tests run:
clear; close; clc
ps. if you have any suggestions for more "stuff" i could/should include in every programme please let me know :)
Matt Fig 2012년 12월 15일
편집: Matt Fig 2012년 12월 15일
You could put that code in an m-file then use COPYFILE to copy it to a new m-file, including the intended name.
Say your above template is saved as func_template.m and you want to make a new function named myfunc.m. Save this:
function  = make_fun(V)
Then from the command line:
Image Analyst 2012년 12월 15일
Here are some lines of code that you might consider putting at the top of your test scripts. Pick and choose which you want:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
% Change the current folder to the folder of this m-file.
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.