strs2mat.m

来自「JLAB is a set of Matlab functions I have」· M 代码 · 共 45 行

M
45
字号
function[mat]=strs2mat(x,flag)%STRS2MAT  Converts a cell array of strings into a string matrix.%%   MAT=STRS2MAT(X) where X is a cell array of strings will return a%   matrix MAT, with rows containing the elements of the cell array.%%   The text in MAT is formatted to be flush on the left.%%   See also FLUSHLEFT, FLUSHRIGHT%   _________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information%   (C) 2003--2006 J.M. Lilly --- type 'help jlab_license' for details        %Flag prevents recursion from flushleftif nargin==1  flag=0;endif ~iscell(x)  xtemp=x;  clear x  x{1}=xtemp;end%x=packstrs(x);M=length(x);for i=1:M    n(i)=length(x{i});endN=max(n);mat=char(32*ones(M,N)); %32 <==> ' ' for i=1:M    if n(i)>0       mat(i,1:n(i))=x{i};    endendif ~flag  mat=flushleft(mat);end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?