help-octave
[Top][All Lists]
Advanced

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

RE: Problem with reading lists


From: Hall, Benjamin
Subject: RE: Problem with reading lists
Date: Tue, 8 Mar 2005 13:10:41 -0500

Not sure I know the best way to convert "list" objects back into a cell
array, one way is with an explicit for-loop using the "nth" function

[a,b,c] = textread('example.csv','%f,%f,%s');

names = {};
for kk = 1:length(c)
   names{kk} = nth(c,kk);
endfor

alternatively, I just noticed a function called csv2cell which could be used
like:

dat = csv2cell('example.csv');

a = [ dat{:,1} ];
b = [ dat{:,2} ];
names = { dat{:,3} };



-----Original Message-----
From: Marcus Vinicius Eiffle Duarte [mailto:address@hidden
Sent: Tuesday, March 08, 2005 12:26 PM
To: address@hidden
Subject: Problem with reading lists


Hey, folks!

I just discovered that textread returns lists, instead of cell arrays.
I didn't find some kind of list2cell function. Is there any built-in
or m-function to convert one to another.
I tried the code

        function cellvar = list2cell( listvar )
        elements = length( listvar );
        cellvar = cell( elements, 1 );
        for aux = 1 : size( listvar, 1 )
                cellvar{ aux } = listvar( aux );
        end

However, when I try 
        x = list(1,2,3,4); 
        xx = list2cell(x);

Octave gives an error and closes.

Weirdly enough, when I try the code

        function cellvar = list2cell( listvar )
        elements = length( listvar );
        cellvar = cell( elements, 1 );
        for aux = 1 : size( listvar, 1 )
                tmp = listvar( aux );
                cellvar{ aux } = tmp;
        end

and run again 
        x = list(1,2,3,4); xx = list2cell(x);

I get the same error. I introduced a "pause" between the lines"tmp =
listvar( aux );" and "cellvar{ aux } = tmp;", and Octave immediately
close before pausing.

I tried onde again, running from octave's prompt
        octave:1> x=list(1,2,3,4);for kk=1:length(x),xx{k}=x(kk),end

and Octave exited again. It also exits if I run
        octave:1> x=list(1,2,3,4);for kk=1:length(x),xx(k)=x(kk),end

And it also exits when running
        octave:1> x=list(1,2,3,4); xx=x(1); 

I can run normally
        octave:1> x=list(1,2,3,4); xx=x;
But if I add to the former code the line (after copying the list)
        octave:2> xx(2)=x(2)
Octave also exits.

I am running Octave 2.1.57 + Octave-Forge 20041116 under Fedora Core 3.
Am I doing something wrong and tremendously stupid here?

Thanks in advance,

Marcus Vinicius Eiffle Duarte



-------------------------------------------------------------
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
-------------------------------------------------------------



-------------------------------------------------------------
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]