function label = num2lab(x,formstr,prestr,poststr)
% NUM2LABEL Converts a numeric vector into a cell vector of strings.
% LABEL = NUM2LABEL(X, F, PREFIX, POSTFIX) converts the vector X into a cell array of strings,
% where each cell contains a string representation of X(j), prefixed by PREFIX
% and postfixed by POSTFIX. The used format for numeric to string conversion
% is the one provided in F.
% As an example, F may be '%d', '%.2f', '%+0.3f', etc...
% Valid formats are the same accepted by SPRINTF.
%
% This function can be helpful in generating legends and ticklabels.
%
% % Examples
% figure
% plot(rand(10,3));
% legend_label=num2lab(1:3,'%d','Random signal #');
% title('Random Fast Fourier Transform amplitude coefficients');
% label=num2lab(1:10,'%d','Coeff #');
% set(gca,'xticklabel',label);
% legend(legend_label);
%
% See also CELLSTR, NUM2STR, SPRINTF
% Copyright: Marco Cococcioni, 2008
% $Revision: 1.1 $ $Date: 2008/07/16 11::02:00 $
%--------------------------------------------------------------------------
if nargin < 1,
disp('At least the vector x has to be provided. Running in demo mode.');
disp('Press a key to continue...');
pause
figure
plot(rand(10,3));
legend_label=num2lab(1:3,'%d','Random signal #');
title('Fast Fourier Transform randomly generated amplitude coefficients');
label=num2lab(1:10,'%d','Coeff #');
set(gca,'xticklabel',label);
legend(legend_label);
return
end
if nargin < 2,
formstr='%d';
end
if nargin < 3,
prestr = '';
end
if nargin < 4,
poststr = '';
end
if not(isvector(x)),
error ('Error: x must be a vector');
end
label = cellstr(num2str(x(:), [prestr formstr poststr]));