Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#5 |
初级会员
注册日期: 2010-06-23
帖子: 3
声望力: 0 ![]() |
![]()
把下面程序复制到m文件取名为Array.m 中,并把Array.m文件放在当前路径下。
function A=Array(array_name,sz) %% 要生成 50×60 符号矩阵 只要使用命令如: %% A=Array('a',[50,60]); B=Array('b',[50,60]); 等等 %% 要生成 600 符号 只要使用命令如: %% V=Array('v',600); U=Array('u',600); 等等 %% 注意第一个输入变量必须是字符,第二个是要生成的符合矩阵或向量的 %% 规模 function [A,array_ustr,array_istr]=Array(array_name,sz) if ischar(array_name) array_name=lower(array_name); else error('It is expected that first input argument is a char array'); end if (length(sz)==2)&&(sz(1)~=1)&&(sz(2)~=1) for it=1:sz(1) for jt=1:sz(2) A(it,jt)=sym([array_name,num2str(it),'_',num2str(jt)]); end end elseif (length(sz)==1)||((length(sz)==2)&&(sz(1)==1))||((length(sz)==2)&&(sz(2)==1)) if length(sz)==1 for kt=1:sz(1) A(kt,1)=sym([array_name,num2str(kt)]); end elseif ((length(sz)==2)&&(sz(1)==1)) for kt=1:sz(2) A(1,kt)=sym([array_name,num2str(kt)]); end else for kt=1:sz(1) A(kt,1)=sym([array_name,num2str(kt)]); end end else error('Demension of Arrary should be less then 3 '); end if length(sz)==2 if (sz(1)>sz(2))&&(sz(2)==1) p=conj(A'); else p=A; end elseif length(sz)==1 p=conj(A'); end p_istr0=char(p); pre='matrix([['; newpre=''; post=']])'; newpost=''; p_istr=strrep(p_istr0,pre,newpre); p_istr=strrep(p_istr,post,newpost); p_ustr=strrep(p_istr,array_name,[array_name,'(']); p_ustr=strrep(p_ustr,',','),'); p_ustr=[p_ustr,')'];%% To make p_ustr in the form p(1),p(2),...,p(end), if arrary_name='p'. if length(sz)==2 if (sz(1)~=1)&&(sz(2)~=1) p_ustr=strrep(p_ustr,'_',','); p_ustr=strrep(p_ustr,[',',num2str(sz(2)),'),'],[',',num2str(sz(2)),')];[']); p_ustr=['[',p_ustr,']']; end end array_ustr=p_ustr; array_istr=p_istr; 此帖于 2010-07-25 20:42 被 bodhitreechen 编辑。 原因: 有更新的m文件版本 |
![]() |
![]() |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
[求助]请教matlab的输出格式问题 | oliver6269 | MATLAB论坛 | 2 | 2008-11-18 21:48 |
[求助]一个很简单的问题,可是就是不知道问题出在哪儿? | pikky | MATLAB论坛 | 6 | 2008-11-17 18:21 |
请教如何实现灰度图像的三维显示 | linxudong | MATLAB论坛 | 1 | 2008-11-16 15:56 |
Enhancing Multicore System Performance Using Parallel Computing with MATLAB | TechnicalArticles | MATLAB技术文章 | 0 | 2008-11-14 03:46 |
向大家请教两个问题!! | whyhzj | MATLAB论坛 | 0 | 2008-10-29 14:37 |