缩放变量的范围 - MATLAB
问题描述:
我有一个变量,1xn
双由连续几年缩放变量的范围 - MATLAB
YEARS = 1900 1901 1902 1903 1904 1905 1906 1907 1908
是否有某种方式能够执行此变量,如下所示的缩放,刚上市的起始日期的任何功能,在一个字符串的结束日期:
YEARS = 1900 - 1908
答
YEARS = [1900 1901 1902 1903 1904 1905 1906 1907 1908];
A = min(YEARS); % Get the minimum value
B = max(YEARS); % Get the maximum value
formatStr = '%d - %d'; % Specify the string format
years = sprintf(formatStr,A,B); % Output the result
你实际上可能直接设置years = sprintf('%d - %d',min(YEARS),max(YEARS));
但是这在我看来的可读性。
+0
@ A. Visser - 非常感谢! – steve
所以你期待输出'8'?不明白你的问题。 – Daniel
什么是您的数据类型?字符串的单元格数组?我不明白 –
@ Daniel&Benoit_11 - 我用更多的信息更新了我的问题。 – steve