Use of 2012 unique version with Matlab 2011a possible?

7 views (last 30 days)
Would it be possible to use the new version of "unique" in an older matlab version? I wrote some code and used "unique" with the 'stable' option and I need to run this code on another computer with Matlab 2011a.
If it's possible: Which files would I need to copy?
  1 Comment
Jan
Jan on 9 May 2012
See also: http://www.mathworks.com/matlabcentral/answers/30956-change-of-set-function-in-the-future

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 May 2012
This would not be permitted under the license agreement, and would not be technically supported.

More Answers (2)

Jan
Jan on 9 May 2012
function [AA, AI, BI] = CStrUnique(A)
% Unique elements of a cell string [MEX]
% [AA, AI, BI] = CStrUnique(A)
% INPUT:
% A: Cell string of any size.
% OUTPUT:
% AA: Cell of unique strings of A. If the input A is a column cell, AA is a
% column cell also. Otherwise AA is a row cell. The comparison considers
% spaces, empty strings and case of letters.
% AI: Linear indices (see IND2SUB) of unique strings such that A(AI) is
% unique. The first occurrence of a string is preferred.
% The order of AI corresponds with the order of strings in A, so AI is
% strict monotonically increasing.
% BI: List of linear indices of input strings according to output:
% AA(BI) = A.
%
% Differences to Matlab's UNIQUE:
% Faster.
% Output is not sorted.
%
% Tested: Matlab 6.5, 7.7, 7.8, 7.13, WinXP/32, Win7/64
% Author: Jan Simon, Heidelberg, (C) 2006-2012 matlab.THISYEAR@nMINUSsimonDOTde
% License: BSD, use, copy, modify on own risk, mention the author
nA = numel(A);
if nA > 1
[As, SV] = sort(A(:));
if nargout < 3
UV(SV) = [1; strcmp(As(2:nA), As(1:nA - 1)) == 0];
AI = find(UV);
else % Indices requested:
UV = [1; strcmp(As(2:nA), As(1:nA - 1)) == 0];
UVs(SV) = UV;
AI = find(UVs);
% Get BI such that AA(BI) == A:
v = zeros(1, nA);
v(AI) = 1:length(AI); % Sequence related to AA
vs = v(SV); % Sorted like A
vf = vs(find(vs)); %#ok<FNDSB> % Just the filled entries
BI(SV) = vf(cumsum(UV)); % Inflate multiple elements
end
elseif nA % Comparison of subsequent elements fails for nA == 1
AI = 1;
BI = 1;
else
AI = [];
BI = [];
end
AA = A(AI);
Example: If the input is the (already unique) list of 961 M-files with full path, this is 18% faster than unique - and unsorted.
  2 Comments
Jan
Jan on 11 May 2012
Perhaps, I'm not shy enough, I know, it would be worth to vote and/or accept this answer. Walter's answer is more correct, but my one is more helpful.

Sign in to comment.


Christopher
Christopher on 9 May 2012
Thank you for your fast answer. Then I have to adjust my algorithm in order to fix this problem.
  2 Comments
Geoff
Geoff on 9 May 2012
That's probably the easiest. Unless you don't rely on the subtleties. For instance, if you don't care which index you get for each unique value you can simply get the stable ordering back..
%%
[~, I] = unique(data);
U_stable = data(sort(I));
%%
Otherwise, you could always write your own slower version of unique in MatLab and use that if the version is less than 2012a, or indeed write one in C with good performance.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!