Comments on: Unique Values Without Rearrangement https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/?s_tid=feedtopost Loren Shure is interested in the design of the MATLAB language. She is an application engineer and writes here about MATLAB programming and related topics. Mon, 08 Jan 2018 20:24:52 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Loren https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30870 Thu, 03 Dec 2009 12:22:11 +0000 https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30870 OysterEngineer-

The first value is unique since there are no other values to compare to, that’s why the leading 1.

I didn’t explain the details of the SortVec and UV because I think it helps to study the help and examples for sort/sortrows to understand and I didn’t feel like reproducing that here.

I converted to double since I have the Symbolic Toolbox on my path and there is an overloaded diff for the char datatype there that produces a derivative, which I didn’t want.

–Loren

]]>
By: OysterEngineer https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30869 Wed, 02 Dec 2009 22:55:09 +0000 https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30869 Your technique is clever, but it is difficult to follow at a glance. You’ve kind of left to the reader several important details. Like:

1. Padding the output of diff with the leading 1.

2. The details of how the chained use of SortVec & UV assures the order is related to the original order that we want.

Also, won’t the technique work properly with the string left in the character class? e.g., why was it necessary to convert the characters to numbers?

]]>
By: Jerker Wågberg https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30851 Thu, 26 Nov 2009 22:19:41 +0000 https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30851 Sorry, the two cents just got devaluated. Should have read the discussion first…

]]>
By: Jerker Wågberg https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30850 Thu, 26 Nov 2009 22:16:33 +0000 https://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/#comment-30850 My two cents and lines:

[~,ix]=unique(myString, 'first');
finalString=myString(sort(ix))
]]>