uniquecell

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - CODING/DEVELOP
Introduced first in SolidGeometry 5.3, Creation date: 2023-06-09, Last change: 2025-09-15

unique command for cells

Description

With each new version of Matlab, the language seems to become more and more class-dependent and lose the flexibility that was one of Matlab's key strengths in the past

This function does what was expected of unique in the past for cell lists and no longer works

See Also:

Example Illustration

 missing image of uniquecell(C)

Syntax

C=uniquecell(C)

Input Parameter

C: cell list

Output Parameter

C: cell list with unique elements

Examples


unique({'A', 2, 4, 6, 'D', 'A'}) % creates an error
uniquecell({'A', 2, 4, 6, 'D', 'A'}) $ creates the expected result




Copyright 2023-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is designed to find unique elements in a cell array, similar to the 'unique' function in MATLAB, but specifically for cell arrays. It addresses the limitations of the 'unique' function when dealing with cell arrays in newer MATLAB versions.

Input Parameters

Output Results

Algorithm Steps

  1. Determine the number of elements in the cell array C using numel.
  2. Create a logical identity matrix ie of size nc x nc.
  3. Reverse the order of elements in C using C(end:-1:1).
  4. Use nested loops to compare each element with every other element in the reversed cell array:
  5. Identify unique elements by summing each row of ie and checking if the sum equals 1.
  6. Filter the cell array C to include only unique elements using the logical index ii.
  7. Find the indices of the unique elements in the original order using find(flipud(ii)).
  8. Reverse the order of the filtered cell array C to restore the original order of unique elements.
Algorithm explaination created using ChatGPT on 2025-08-19 00:17. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21