help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Cell arrays of strings in "sort" and "unique"


From: Keith Goodman
Subject: RE: Cell arrays of strings in "sort" and "unique"
Date: Mon, 13 Sep 2004 17:08:31 -0700

The code below, unique_cell, doesn't work

1. The minus sign should be moved one line down (-y)
2. I just updated to 2.1.58 which gives a different result for
num2str([1 2; 3 4]) than 2.1.57
3. My strings are short; if yours are long then the numbers get too
big which means characters at the end will be ignored.
4. ASCII code like 12 3 45 is incorrectly assumed to be equal to 123 4 5.

In other words, does anyone know a quick (minimal looping) routine for
a unique on cell arrays on strings?

---------- Forwarded message ----------
From: Keith Goodman <address@hidden>
Date: Mon, 13 Sep 2004 15:19:38 -0700
Subject: Cell arrays of strings in "sort" and "unique"
To: address@hidden

I noticed that the functions "sort and "unique" do not support cell
arrays of strings. And that sort does not support strings.

As a work around for unique, I'm using

function [z,i] = unique_cell(x)
x = x(:);
y = str2num(num2str(-1*char(x)));
[ignore,i] = unique(y);
z = x(i,:);

Could the above technique of converting a cell array to a char array
to a number matrix to a string array to a number array be used in sort
and unique to handle cell arrays of strings?



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]