Newline.m

From Pnb
Revision as of 15:48, 5 August 2010 by 128.111.101.185 (talk) (Created page with '<pre> function new_string=newline(old_string) % function new_string=newline(old_string) % % makes an array from a string which contains % carriage returns (e.g., string=ls). …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
function new_string=newline(old_string)
% function new_string=newline(old_string)
%   
% makes an array from a string which contains 
% carriage returns (e.g., string=ls).  The
% array will be padded with blanks to insure that
% all rows have the same number of columns.

if (abs(old_string(length(old_string)))~=10)
	old_string=[old_string,setstr(10)];
end

i=[0,find(abs(old_string)==10)];

new_string=setstr(32*ones(length(i)-1,max(diff(i))-1));

for string=1:(length(i)-1),
	start=i(string)+1; stop=i(string+1)-1;	len=stop-start+1;
	if (stop-start)>=1
		new_string(string,1:len) = old_string(start:stop);
	end
end

newline