📄 strings_format.m
字号:
function [out_s, len] = strings_format(s, min_len, max_len)
% -------------------------------------------------------------------------
% this code is part of the 'Reduction Testbench' suite
% developed by A. Manganaro, R. Todeschini, A. Ballabio, D. Mauri
% 2006 - Milano Chemometrics and QSAR Research Group
% -------------------------------------------------------------------------
%
%
% [out_s, len] = strings_format(s, min_len, max_len)
%
% strings_format formats the given strings array, putting blanks in each
% string in order to have the same length for each of them. This lenght is
% bound to the min and max values given as input.
%
% Input:
% s = strings array
% min_len = minimum length for each string
% max_len = mazimum length for each string
%
% Output:
% out_s = formatted strings array
% len = length of the formatted strings
echo off;
len = 0;
% Find max length
for idx=1:length(s)
if (length(s{idx})>len)
len = length(s{idx});
end
end
% Sets len checking user's max and min length
if (len>max_len) len = max_len; end
if (len<min_len) len = min_len; end
for idx=1:length(s)
s{idx} = str_format(s{idx},len);
end
out_s = s;
echo on;
function out_s = str_format(s, len)
% str_format si a subfunction that trims a string to the given length
% value; if the string is shorter than the given value, it is filled with
% blanks until it reaches the correct length
%
% Input:
% s = string
% len = length
%
% Output:
% out_s = formatted string
if (len<1)
out_s = s;
return;
end
if length(s)>len
out_s = s(1:len);
return;
end
blank_str = ' ';
for idx = 2:len
blank_str = [blank_str ' '];
end
out_s = [s blank_str];
out_s = out_s(1:len);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -