No BSD License  

Highlights from
SCLRCMPRS

from SCLRCMPRS by Mukhtar Ullah
Squeezes nonscalar arrays to scalars, if possible.

sclrcmprs(varargin)
function [varargout] = sclrcmprs(varargin)
% SCLRCMPRS squeezes nonscalar arrays to scalars, if possible.
%    SCLRCMPRS(X) returns a scalar element if the array X is only the
%    repetition of this scalar, X otherwise.
%    [X1,X2,...,Xn] = SCLRCMPRS(X1,X2,...,Xn) replaces non-scalar
%    arrays having the same scalar repeated, with the scalars.
%
% Example:
% >> c1 = magic(4); c2 = repmat(2,5); c3 = 15; c4 = [9 9];
% >> [c1,c2,c3,c4] = sclrcmprs(c1,c2,c3,c4)
% 
% c1 =
% 
%     16     2     3    13
%      5    11    10     8
%      9     7     6    12
%      4    14    15     1
% 
% 
% c2 =
% 
%      2
% 
% 
% c3 =
% 
%      15
% 
% 
% c4 =
% 
%      9
% 

% Mukhtar Ullah
% November 29, 2004
% mukhtar.ullah@informatik.uni-rostock.de

C = varargin;
n = nargin;

for k = 1:n
    if C{k} == C{k}(1)
        C{k}(2:end) = [];
    end
end

varargout = C;

Contact us at files@mathworks.com