option is used.OPTIONS:a
m的文件夹都Add Folder进去,接着随便选一个pathdef.m文件复制到安装目录下MATLAB\R2010b\toolbox\local文件夹里,save并关闭;最后再次file->set path->default,然后save关闭,后面提示都选yes就解决了。
改文件名试试,应该跟程序的默认文件名冲突了。比如原来文件名是max,可以改为max1,应该就可以运行了
你设置MATLAB的默认路径了吗?若没有通过file->setpath设置一下。若你想调用存在于目录文件夹之下的.dat 数据文件,在command窗口中输入》load *(filename).dat即可。
这里只是提示,由于你的Simulink模型里面没有连续的变量,再求解模型时就没有使用ode45求解,而是使用'VariableStepDiscrete'求解器,属于matlab自动判断,这个警告只是提示你的。不影响计算结果。你可以让这个警告不显示,通过在Confi
换个文件名保存。有untitled1这个文件存在了。也可以选择覆盖。
matlab Warning: The model name 'untitled1' is shadowing another name in the MATLAB workspace or pa
matlab里面所有的程序都是以m文件文件的形式保存,运行都是运行m文件。所以,对于guide生成的GUI程序,打开的方式有两种:一是打开其m文件,点击m文件上的运行按钮,会自动弹出figure来。二是通过guide打开fig文件,点击gui编辑
首先,直接运行.fig文件不会执行m文件中的OpeningFcn和CreateFcn。\x0d\x0aOpeningFcn函数中有两句至关重要:\x0d\x0a% Choose default command line output for **\x0d\x0ahandles.output = hObject;\x0d\x0a%
2.重命名时,另存为的方法是对的,需要对.m文件和.fig文件均要另存为,这样都进行另存为才可以正常运行。
输入guide或者 点击 然后出来个窗口 选择open existing gui 点击Browser 找到你要打开的fig文件
1.你的程序里是zd按照符号运算的。符号运算不用plot,好像用要用ezplot的。2.我不知道版你程序里的权物理概念,但改一下就行:syms L I Rs Rr a Rg Z x y I=1000 L=2 Rg=15 Rs=0.026 Rr=0.0001 Z=(Rg
fig的属性里面有一个Name选项,将其值改为中文名字再运行就可以了
matlab的gui中*.fig已经保存文件名,为什么运行时还Untitled
那么很显然你的错误就是,没有把当前定义好。下面给出代码:H1=20;H2=20;H3=20;g=9.8;h1 =[ ];h2=[ ];h3=[];i=0;for t =0:0.01:10i=i+1;%%设置下标,来表示当前h1,h2,h3的元素if (sqrt(H1)-0.
可能的原因是,这段程序本来用于处理别的图像文件,被你换了一张图片。程序原来处理的图片应该是索引色的(indexed image),图像数据是二维数组,而你现在的图片是真彩色(RGB image),图像数据是三维数组,所以,在上面一行
一、右击 授予访问权限 二、点击特定用户 三、将everyone那里改为读取/写入,就可以了
应该是c或c++了,VB和Delphi也接触过,我想版面(matlab版)大部分人也差不多),如果你抱着“把其他语言的思想运用在matlab里面”的话,那么我想,即使程序运行不 出错,也很难把握matlab的精髓,也就很难发挥matlab的作
你的目的是将data1加载为变量名为c1的变量,但这里可能出了问题。将load data1 c1换为 s=load('data1.mat');sc=struct2cell(s);c1=cell2mat(sc);如果你知道data1里变量的名称且不想改为另外的名字的话,直接load
Matlab老是报错出错untitled>QPSKsave(’signal.mat’,’m’)
调用出错,没有定义函数user_gngauss(M,sgma)
year,population,'*',year2,population2,'X',year1,population1);legend('实际数据','拟合数据')xlabel('年份');ylabel('人口数量(亿人)')主要是把Y改为y,P改为p,最后一行应为ylabel()。已经改正,复制即可
数组越界了,看看wz{c(1)}中c(1)的值,再看看wz的长度
function [db,mag,pha,grd,w] = freqz_m(b,a);[H,w] = freqz(b,a,1000,'whole');H = (H(1:1:501))'; w = (w(1:1:501))';mag = abs(H);db = 20*log10((mag+eps)/max(mag));pha = an
[I map]=imread('c:\美女\杨明菲131027 1.jpg','jpg'); %图像数据的读取,将图像数据放入矩阵A中,颜色数据放入矩阵M中 imshow(I,map);
可能的原因是,这段程序本来用于处理别的图像文件,被你换了一张图片。程序原来处理的图片应该是索引色的(indexed image),图像数据是二维数组,而你现在的图片是真彩色(RGB image),图像数据是三维数组,所以,在上面一行
MATLAB程序执行后出现这种情况,请大神知道,急急急!!!Error in ==> Untitled at 10 if mask(i,j)==0;
修改建议 把程序原来的第一行 img=double(imread('C:\Users\lenovo\Desktop\wj.jpg'));改为 img=imread('C:\Users\lenovo\Desktop\wj.jpg');if ndims(img) > 2 [img,map] = rgb2ind(img, 256);endimg =
这个是提示第7行出现了错误。根据题主的问题 错误发生在f1=(99*cos(x)*(99*sin(x) + 15))/((99*sin(x) + 15)^2 + 24025)^(1/2) - 99*sin(x); 这一句当中 根据分析表达式,错误应该是矩阵乘法中维数不
1.你的程序里是zd按照符号运算的。符号运算不用plot,好像用要用ezplot的。2.我不知道版你程序里的权物理概念,但改一下就行:syms L I Rs Rr a Rg Z x y I=1000 L=2 Rg=15 Rs=0.026 Rr=0.0001 Z=(Rg
所谓untitled的意思就是“没有命名的文件”,属于matlab默认文件名。当你保存文件时,如果不修改文件名,系统以untitled为名字保存。
n=1;while prod(1:n) < 1e100 n=n+1;end n 结果:n = 70 后面加个n就ok。
Matlab 显示untitled
这个是提示第7行出现了错误。根据题主的问题 错误发生在f1=(99*cos(x)*(99*sin(x) + 15))/((99*sin(x) + 15)^2 + 24025)^(1/2) - 99*sin(x); 这一句当中 根据分析表达式,错误应该是矩阵乘法中维数不匹配造成,原表达式应改为: f1=(99*cos(x).*(99*sin(x) + 15))./((99*sin(x) + 15)^2 + 24025).^(1/2) - 99*sin(x);所谓untitled的意思就是“没有命名的文件”,属于matlab默认文件名。当你保存文件时,如果不修改文件名,系统以untitled为名字保存。
这个是提示第7行出现了错误。根据题主的问题 错误发生在f1=(99*cos(x)*(99*sin(x) + 15))/((99*sin(x) + 15)^2 + 24025)^(1/2) - 99*sin(x); 这一句当中 根据分析表达式,错误应该是矩阵乘法中维数不匹配造成,原表达式应改为: f1=(99*cos(x).*(99*sin(x) + 15))./((99*sin(x) + 15)^2 + 24025).^(1/2) - 99*sin(x);
将Figure需要改为小写哈figure;另外Inshow函数应该是Imshow函数哈
MATLAB是一种对技术计算高性能的语言。 它集成了计算,可视化和编程于一个易用的环境中,在此环境下,问题和解答都表达为我们熟悉的数学符号。 典型的应用有: 数学和计算 算法开发 建模,模拟和原形化 数据分析,探索和可视化 科学与工程制图 应用开发,包括图形用户界面的建立 MATLAB是一个交互式的系统,其基本数据元素是无须定义维数的数组。 这让你能解决很多技术计算的问题,尤其是那些要用到矩阵和向量表达式的问题。而要花的时间则只是用一种标量非交互语言(例如C或Fortran)写一个程序的时间的一小部分。
一、字符和字符串 在MATLAB中不管是字符,还是字符串都是用单引号。而在C、C++、C#、Java等语言中,字符是用单引号的,字符串则必须用双引号。因此在MATLAB中如果需要在字符串中用到单引号的话,就要用两个单引号来代替。 如: >> a='this''is an apple' a = this'is an apple 同理,如果字符串中需要双引号的话,可以用四个单引号来代替。如下: >> b='I''''am Tim' b = I''am Tim 在MATLAB中的字符串连接,我们可以使用一对中括号。当然,这种连接方式也适用于向量、矩阵等的连接。如下: >> c=[a b] c = this'is an appleI''am Tim >> a1=[1 2];b1=[3 4]; >> c1=[a1 b1] c1 = 1 2 3 4 >> c2=[a1;b1] c2 = 1 2 3 4 但是,对于字符串的连接不能使用加号(+)来进行。这点和在C++、C#、Java等语言中是不一样的。因为在MATLAB中这些字符串也是以矩阵的形式存储的,你要是用加号的话,需要两个矩阵的大小一致。比如: >> a2='hello';b2='mustb'; >> a2+b2 ans = 213 218 223 224 209 但是,很明显,加完之后都是一系列的值了。本来,这些字符串也是以数值的形式存储的。而我们要取的字符串中某一个字符的时候,也是很方便的,直接像引用矩阵的元素一样。如下: >> a2(1) ans = h >> a2(4) ans = l >> find(a2>'i') ans = 3 4 5 可以看到,a2里面在字母i后面的字符有第3、4、5个字符,也就是llo了。 在MATLAB中要将一个数字转换为字符可以用num2str,将字符转换为数字可以用str2num。如下: >> stra1=num2str(a1) stra1 = 1 2 >> class(stra1) ans = char >> strb1='[3 4]'; >> str2num(strb1) ans = 3 4 对于strb1,我们可以使用eval函数,该函数可以将字符串作为一个MATLAB命令去执行。如下: >> p=eval(strb1) p = 3 4 相当于p=[3 4]。 当然了,C语言里面的sprintf、fprintf函数我们都是可以在MATLAB中使用的。比如: >> sprintf('Tim is %d years old.',24) ans = Tim is 24 years old. 至于fprintf函数,则需要用fopen去打开一个文件,然后写入数据进去。如下: >> fd=fopen('a.txt','w+'); >> fprintf(fd,'I am Tim.\n'); >> fprintf(fd,'My age is %d\n',24); >> fclose(fd); 然后,用MATLAB Editor打开MATLAB当前目录下的a.txt就可以看到: 但是,当你用记事本打开的时候会看到: 这是因为在Windows上要想换行需要\r\n,而不能单是\n。 二、if语句、for语句、switch语句、while语句、try-catch语句都以end结尾 在MATLAB中,没有goto和do…loop和do…while语句。而且语句的结尾都是以end结尾的。 >> t=4; >> if(t<5),disp('t is smaller than 5.'),end t is smaller than 5. 当然,if语句也可以有else语句。 >> if(t>5),disp('t is bigger than 5.'),else,disp('t is smaller than 5.'),end t is smaller than 5. 还可以用elseif。 >> if(t>5),disp('t is bigger than 5.'),elseif(t==5),disp('t is equal 5.'),else,disp('t is smaller than 5.'),end t is smaller than 5. 在MATLAB中,由于矩阵的索引都是从1开始的,这点和C、C++、C#、JAVA等语言是不一样的。所以,在循环的时候建议从1开始循环,而且循环的时候不推荐用变量i和j。因为这两个变量在MATLAB中表示的是复数的虚部变量。当然,如果你的程序里面没有复数,就不用怕。如果有复数,就要小心了。 之所以从1开始,是因为大多数时候我们使用循环是为了依次能访问到矩阵的每一个元素,所以,如果矩阵的索引出现了0,那么就会报出错误。所以,从1开始循环,是一种很好的习惯,而不是要求你必须这样做。 而且,在for循环中,你的循环变量不仅可以是一个数,也可以是一个向量。看下面的程序: >> aa=[1 2;3 4; 5 6;7 8]; >> for i=aa,disp(i),end 1 3 5 7 2 4 6 8 >> aa aa = 1 2 3 4 5 6 7 8 也就是说,i第一次的值是aa的第一列,i第二次的值是aa的第二列。这样的话,这个循环变量i就不仅仅是一个数了,二是一列数。 在MATLAB中,switch语句中是不用break的,而且默认的选项不是default,而是otherwise。如下: a=5; switch(a), case 1, disp('a is 1.'); case 2, disp('a is 2.'); case 5, disp('a is 5.'); otherwise, disp('sorry, i do not know.'); end 还需要注意的是case后面没有分号,而C、C++、C#、Java等语言中是必须是分号的。在MATLAB中可是没有分号,我程序中的逗号,也可以是没有的。指向上面的程序,在MATLAB中的输出是: a is 5. 至于while语句的使用和C、C++、C#、Java等语言中的while基本上是一致的。如下: a=5; b=0; while a>0 b=b+a; a=a-1; end b a Matlab命令窗口的输出是这样的: b = 15 a = 0 try-catch语句一般是用来捕捉错误的。 try a=input('Input a number: '); catch error('unknown error.'); end 当运行上面的程序,在MATLAB中输入: Input a number: # ??? Error using ==> tim_try at 4 unknown error. 三、变量不用声明 在MATLAB中的变量是可以不用声明的,这点和C类语言和Java是有很大区别的。但是,为了程序更清晰和加快程序的执行速度,提供初始化和声明有时是必要的。不如, b=[]; for i=1:10 b=[b i]; end b 在MATLAB命令窗口的输出如下: b = 1 2 3 4 5 6 7 8 9 10 如果你不初始化b为空的话,如下: for i=1:10 b=[b i]; end b 在命令窗口的输出如下:??? Undefined function or variable 'b'. 上面说过了,中括号[]可以用来合并向量的,这里变量b不存在,因此不能合并。所以会出错。 四、没有++、--操作符 在MATLAB中是没有++和--操作符的,因此需要转换。如a++; 可以转化为a=a+1;至于++a;你只需要将a=a+1的位置放到前面就可以了。 五、点乘、点除,但没有点加、点减 在点乘,是矩阵中的对应元素相乘。而不是矩阵的乘法。点除也是同样道理,对应元素想除。至于点加,就相当于加法。因为加减法本身就是对应元素的加减。 六、左除和右除 在C类和Java等语言中,除法就是一个操作符(/),但在MATLAB中(/)和(\)是有区别的。/代表的是右除,\代表的是左除。 >> A=[1 2;3 4];B=[5 6;7 8]; >> C1=A\B C1 = -3 -4 4 5 所以A左除B,就相当于A的逆矩阵乘B。 >> inv(A)*B ans = -3.0000 -4.0000 4.0000 5.0000 那么可想而知,A右除B,就相当于A乘B的逆矩阵。 >> A/B ans = 3.0000 -2.0000 2.0000 -1.0000 >> A*inv(B) ans = 3.0000 -2.0000 2.0000 -1.0000 七、MATLAB的编程思想 当你用MATLAB来写程序的时候,尽量以向量、矩阵为单位来考虑问题。也就是在MATLAB中常常能用一个点乘来代替多个循环的操作。也就是用向量化的操作来代替循环,这样能够大大的提高MATLAB程序的运行速度。 举个简单的例子: clear all clc a=round(rand(100)*100); b=round(rand(100)*100); tic f1=a.*b; toc tic for i=1:100, for j=1:100, f2(i,j)=a(i,j)*b(i,j); end end toc 在命令窗口的输出如下: Elapsed time is 0.000035 seconds. Elapsed time is 0.001871 seconds. 如果我们给f2初始化下,看看能不能加快速度。 clear all clc a=round(rand(100)*100); b=round(rand(100)*100); tic f1=a.*b; toc f2=zeros(100); tic for i=1:100, for j=1:100, f2(i,j)=a(i,j)*b(i,j); end end toc 此时,命令窗口的输出如下: Elapsed time is 0.000024 seconds. Elapsed time is 0.000147 seconds. 可以看到后面的循环的时间明显提高了很多。那么我们为上面的点乘运算的f1也初始化的话,速度会如何? Elapsed time is 0.000022 seconds. Elapsed time is 0.000146 seconds. 可以看到速度提升的不是很明显。如果你将a和b的维数增长到10000的话,提示的速度就明显了很多了。
将a.fig的NAME属性改为b即可。 新文件生成是缺省的NAME属性名与文件名相同。 View-〉PropertyInspector中的NAME属性。
pushbutton的callback 你连pushbutton都没有肯定无法调用
没有xlswrite函数,我这个版本有,你自己拷去建个m文件 function [success,message]=xlswrite(file,data,sheet,range) % XLSWRITE Stores numeric array or cell array in Excel workbook. % [SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY,SHEET,RANGE) writes ARRAY to the Excel % workbook, FILE, into the area, RANGE in the worksheet specified in SHEET. % FILE and ARRAY must be specified. If either FILE or ARRAY is empty, an % error is thrown and XLSWRITE terminates. The first worksheet of the % workbook is the default. If SHEET does not exist, a new sheet is added at % the end of the worksheet collection. If SHEET is an index larger than the % number of worksheets, new sheets are appended until the number of worksheets % in the workbook equals SHEET. The size defined by the RANGE should fit the % size of ARRAY or contain only the first cell, e.g. 'A2'. If RANGE is larger % than the size of ARRAY, Excel will fill the remainder of the region with % #N/A. If RANGE is smaller than the size of ARRAY, only the sub-array that % fits into RANGE will be written to FILE. The success of the operation is % returned in SUCCESS and any accompanying message, in MESSAGE. On error, % MESSAGE shall be a struct, containing the error message and message ID. % See NOTE 1. % % To specify SHEET or RANGE, but not both, you can call XLSWRITE with % just three inputs. If the third input is a string that includes a colon % character (e.g., 'D2:H4'), it specifies RANGE. If it is not (e.g., % 'SALES'), it specifies the worksheet to write to. See the next two % syntaxes below. % % [SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY,SHEET) writes ARRAY to the Excel % workbook, FILE, starting at cell A1 and using SHEET as described above. % % [SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY,RANGE) writes ARRAY to the Excel % workbook, FILE, in the first worksheet and using RANGE as described above. % % [SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY) writes ARRAY to the Excel % workbook, FILE, starting at cell A1 of the first worksheet. The return % values are as for the above example. % % XLSWRITE ARRAY FILE, is the command line version of the above example. % % INPUT PARAMETERS: % file: string defining the workbook file to write to. % Default directory is pwd; default extension 'xls'. % array: m x n numeric array or cell array. % sheet: string defining worksheet name; % double, defining worksheet index. % range: string defining data region in worksheet, using the Excel % 'A1' notation. % % RETURN PARAMETERS: % SUCCESS: logical scalar. % MESSAGE: struct containing message field and message_id field. % % EXAMPLES: % % SUCCESS = XLSWRITE('c:\matlab\work\myworkbook.xls',A,'A2:C4') will write A to % the workbook file, myworkbook.xls, and attempt to fit the elements of A into % the rectangular worksheet region, A2:C4. On success, SUCCESS will contain true, % while on failure, SUCCESS will contain false. % % NOTE 1: The above functionality depends upon Excel as a COM server. In % absence of Excel, ARRAY shall be written as a text file in CSV format. In % this mode, the SHEET and RANGE arguments shall be ignored. % % See also XLSREAD, WK1WRITE, CSVWRITE. % % Copyright 1984-2007 The MathWorks, Inc. % $Revision: 1.1.6.14 $ $Date: 2007/12/06 13:30:16 $ %============================================================================== % Set default values. Sheet1 = 1; if nargin < 3 sheet = Sheet1; range = ''; elseif nargin < 4 range = ''; end if nargout > 0 success = true; message = struct('message',{''},'identifier',{''}); end % Handle input. try % handle requested Excel workbook filename. if ~isempty(file) if ~ischar(file) error('MATLAB:xlswrite:InputClass','Filename must be a string.'); end % check for wildcards in filename if any(findstr('*', file)) error('MATLAB:xlswrite:FileName', 'Filename must not contain *.'); end [Directory,file,ext]=fileparts(file); if isempty(ext) % add default Excel extension; ext = '.xls'; end file = abspath(fullfile(Directory,[file ext])); [a1 a2] = fileattrib(file); if a1 && ~(a2.UserWrite == 1) error('MATLAB:xlswrite:FileReadOnly', 'File cannot be read-only.'); end else % get workbook filename. error('MATLAB:xlswrite:EmptyFileName','Filename is empty.'); end % Check for empty input data if isempty(data) error('MATLAB:xlswrite:EmptyInput','Input array is empty.'); end % Check for N-D array input data if ndims(data)>2 error('MATLAB:xlswrite:InputDimension',... 'Dimension of input array cannot be higher than two.'); end % Check class of input data if ~(iscell(data) || isnumeric(data) || ischar(data)) && ~islogical(data) error('MATLAB:xlswrite:InputClass',... 'Input data must be a numeric, cell, or logical array.'); end % convert input to cell array of data. if iscell(data) A=data; else A=num2cell(data); end if nargin > 2 % Verify class of sheet parameter. if ~(ischar(sheet) || (isnumeric(sheet) && sheet > 0)) error('MATLAB:xlswrite:InputClass',... 'Sheet argument must be a string or a whole number greater than 0.'); end if isempty(sheet) sheet = Sheet1; end % parse REGION into sheet and range. % Parse sheet and range strings. if ischar(sheet) && ~isempty(strfind(sheet,':')) range = sheet; % only range was specified. sheet = Sheet1;% Use default sheet. elseif ~ischar(range) error('MATLAB:xlswrite:InputClass',... 'Range argument must be a string in Excel A1 notation.'); end end catch exception if ~isempty(nargchk(2,4,nargin)) error('MATLAB:xlswrite:InputArguments',nargchk(2,4,nargin)); else success = false; message = exceptionHandler(nargout, exception); end return; end %------------------------------------------------------------------------------ % Attempt to start Excel as ActiveX server. try Excel = actxserver('Excel.Application'); catch exception %#ok warning('MATLAB:xlswrite:NoCOMServer',... ['Could not start Excel server for export.\n' ... 'XLSWRITE will attempt to write file in CSV format.']); if nargout > 0 [message.message,message.identifier] = lastwarn; end % write data as CSV file, that is, comma delimited. file = regexprep(file,'(\.xls)$','.csv'); % change extention to 'csv'. try dlmwrite(file,data,','); % write data. catch exception exceptionNew = MException('MATLAB:xlswrite:dlmwrite', 'An error occurred on data export in CSV format.'); exceptionNew = exceptionNew.addCause(exception); if nargout == 0 % Throw error. throw(exceptionNew); else success = false; message.message = exceptionNew.getReport; message.identifier = exceptionNew.identifier; end end return; end %------------------------------------------------------------------------------ try % Construct range string if isempty(strfind(range,':')) % Range was partly specified or not at all. Calculate range. [m,n] = size(A); range = calcrange(range,m,n); end catch exception success = false; message = exceptionHandler(nargout, exception); return; end %------------------------------------------------------------------------------ try bCreated = false; if ~exist(file,'file') % Create new workbook. bCreated = true; %This is in place because in the presence of a Google Desktop %Search installation, calling Add, and then SaveAs after adding data, %to create a new Excel file, will leave an Excel process hanging. %This workaround prevents it from happening, by creating a blank file, %and saving it. It can then be opened with Open. ExcelWorkbook = Excel.workbooks.Add; ExcelWorkbook.SaveAs(file) ExcelWorkbook.Close(false); end %Open file ExcelWorkbook = Excel.workbooks.Open(file); if ExcelWorkbook.ReadOnly ~= 0 %This means the file is probably open in another process. error('MATLAB:xlswrite:LockedFile', 'The file %s is not writable. It may be locked by another process.', file); end try % select region. % Activate indicated worksheet. message = activate_sheet(Excel,sheet); % Select range in worksheet. Select(Range(Excel,sprintf('%s',range))); catch exceptionInner % Throw data range error. throw(MException('MATLAB:xlswrite:SelectDataRange', sprintf('Excel returned: %s.', exceptionInner.message))); end % Export data to selected region. set(Excel.selection,'Value',A); ExcelWorkbook.Save ExcelWorkbook.Close(false) % Close Excel workbook. Excel.Quit; catch exception try ExcelWorkbook.Close(false); % Close Excel workbook. catch end Excel.Quit; delete(Excel); % Terminate Excel server. if (bCreated && exist(file, 'file') == 2) delete(file); end success = false; message = exceptionHandler(nargout, exception); end %-------------------------------------------------------------------------- function message = activate_sheet(Excel,Sheet) % Activate specified worksheet in workbook. % Initialise worksheet object WorkSheets = Excel.sheets; message = struct('message',{''},'identifier',{''}); % Get name of specified worksheet from workbook try TargetSheet = get(WorkSheets,'item',Sheet); catch exception %#ok % Worksheet does not exist. Add worksheet. TargetSheet = addsheet(WorkSheets,Sheet); warning('MATLAB:xlswrite:AddSheet','Added specified worksheet.'); if nargout > 0 [message.message,message.identifier] = lastwarn; end end % activate worksheet Activate(TargetSheet); %------------------------------------------------------------------------------ function newsheet = addsheet(WorkSheets,Sheet) % Add new worksheet, Sheet into worsheet collection, WorkSheets. if isnumeric(Sheet) % iteratively add worksheet by index until number of sheets == Sheet. while WorkSheets.Count < Sheet % find last sheet in worksheet collection lastsheet = WorkSheets.Item(WorkSheets.Count); newsheet = WorkSheets.Add([],lastsheet); end else % add worksheet by name. % find last sheet in worksheet collection lastsheet = WorkSheets.Item(WorkSheets.Count); newsheet = WorkSheets.Add([],lastsheet); end % If Sheet is a string, rename new sheet to this string. if ischar(Sheet) set(newsheet,'Name',Sheet); end %------------------------------------------------------------------------------ function [absolutepath]=abspath(partialpath) % parse partial path into path parts [pathname filename ext] = fileparts(partialpath); % no path qualification is present in partial path; assume parent is pwd, except % when path string starts with '~' or is identical to '~'. if isempty(pathname) && isempty(strmatch('~',partialpath)) Directory = pwd; elseif isempty(regexp(partialpath,'(.:|\\\\)','once')) && ... isempty(strmatch('/',partialpath)) && ... isempty(strmatch('~',partialpath)); % path did not start with any of drive name, UNC path or '~'. Directory = [pwd,filesep,pathname]; else % path content present in partial path; assume relative to current directory, % or absolute. Directory = pathname; end % construct absulute filename absolutepath = fullfile(Directory,[filename,ext]); %------------------------------------------------------------------------------ function range = calcrange(range,m,n) % Calculate full target range, in Excel A1 notation, to include array of size % m x n range = upper(range); cols = isletter(range); rows = ~cols; % Construct first row. if ~any(rows) firstrow = 1; % Default row. else firstrow = str2double(range(rows)); % from range input. end % Construct first column. if ~any(cols) firstcol = 'A'; % Default column. else firstcol = range(cols); % from range input. end try lastrow = num2str(firstrow+m-1); % Construct last row as a string. firstrow = num2str(firstrow); % Convert first row to string image. lastcol = dec2base27(base27dec(firstcol)+n-1); % Construct last column. range = [firstcol firstrow ':' lastcol lastrow]; % Final range string. catch exception %#ok error('MATLAB:xlswrite:CalculateRange', 'Invalid data range: %s.', range); end %---------------------------------------------------------------------- function string = index_to_string(index, first_in_range, digits) letters = 'A':'Z'; working_index = index - first_in_range; outputs = cell(1,digits); [outputs{1:digits}] = ind2sub(repmat(26,1,digits), working_index); string = fliplr(letters([outputs{:}])); %---------------------------------------------------------------------- function [digits first_in_range] = calculate_range(num_to_convert) digits = 1; first_in_range = 0; current_sum = 26; while num_to_convert > current_sum digits = digits + 1; first_in_range = current_sum; current_sum = first_in_range + 26.^digits; end %------------------------------------------------------------------------------ function s = dec2base27(d) % DEC2BASE27(D) returns the representation of D as a string in base 27, % expressed as 'A'..'Z', 'AA','AB'...'AZ', and so on. Note, there is no zero % digit, so strictly we have hybrid base26, base27 number system. D must be a % negative integer bigger than 0 and smaller than 2^52. % % Examples % dec2base(1) returns 'A' % dec2base(26) returns 'Z' % dec2base(27) returns 'AA' %----------------------------------------------------------------------------- d = d(:); if d ~= floor(d) || any(d(:) 1/eps) error('MATLAB:xlswrite:Dec2BaseInput',... 'D must be an integer, 0 <= D <= 2^52.'); end [num_digits begin] = calculate_range(d); s = index_to_string(d, begin, num_digits); %------------------------------------------------------------------------------ function d = base27dec(s) % BASE27DEC(S) returns the decimal of string S which represents a number in % base 27, expressed as 'A'..'Z', 'AA','AB'...'AZ', and so on. Note, there is % no zero so strictly we have hybrid base26, base27 number system. % % Examples % base27dec('A') returns 1 % base27dec('Z') returns 26 % base27dec('IV') returns 256 %----------------------------------------------------------------------------- if length(s) == 1 d = s(1) -'A' + 1; else cumulative = 0; for i = 1:numel(s)-1 cumulative = cumulative + 26.^i; end indexes_fliped = 1 + s - 'A'; indexes = fliplr(indexes_fliped); indexes_in_cells = mat2cell(indexes, 1, ones(1,numel(indexes))); d = cumulative + sub2ind(repmat(26, 1,numel(s)), indexes_in_cells{:}); end %------------------------------------------------------------------------------- function messageStruct = exceptionHandler(nArgs, exception) if nArgs == 0 throwAsCaller(exception); else messageStruct.message = exception.message; messageStruct.identifier = exception.identifier; end
笔记本的USB转串口可能有兼容问题,改成台式机就可以用了。