help-octave
[Top][All Lists]
Advanced

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

Re: Loading matrix of string and numbers


From: fork
Subject: Re: Loading matrix of string and numbers
Date: Wed, 16 Feb 2011 16:54:39 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

AlbFrigerio <alberto.frigerio1 <at> studenti.unimi.it> writes:

> By the way, the question is quite simple: is it possible to load a matrix A
> which consts of both string (first column) and numbers (second one), so that
> A(i,1) returns a string and A(i,2) a number? See the attached file for a
> simple (stupid) example.

It actually isn't that simple in Octave/ML, because regularly matrices are
numeric only (or character only, but you don't want to go there).  If you want
mixed types in the same matrix, you can only use cell arrays, which are limited
in that you can't use most things like sum, etc.

If possible, you might recode your data outside of octave to give integers to
all the string values.  Octave and its proprietary inspiration aren't very good
at handling categorical or string data, at least not yet ....

> I tried to use [a,b]=textread("test.txt",'%s %d') , but I got a cell array
> (a) and a vector (b) and, even it is a acceptable solution, it is not the
> one I'd like: if I got a lot of columsn I should use [a,b,c,d, ... , goofy,
> mickey, donald , ... , antares, betelgeus, aldebaran, ...] =
> textread("test.txt",'%s %d %s ... ') , and it is not smart :)

That is probably the best solution except for dataframe, which is experimental
but very promising.



reply via email to

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