help-octave
[Top][All Lists]
Advanced

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

Re: Joining arrays


From: Judd Storrs
Subject: Re: Joining arrays
Date: Tue, 23 Jun 2009 21:41:41 -0400

Maybe this can help get you closer (cell/matrix conversions drive me nuts):

pkg load miscellaneous
pkg load io

A = csv2cell ( "FileA" );
T = A (:,1);
B = dlmread ( "FileA", "," );

f = [ 1 2 3 ] ;
r = rows ( B );
C1 = conv ( B(2:r,2), f );
C2 = rot90 ( C1 );

T(:,2) = cat ( 1, cellstr("Bx"), num2cell(C2(1:r-1)) ) ;
cell2csv("FileB",T) ;

--judd



On Tue, Jun 23, 2009 at 8:58 PM, CLOSE Dave <address@hidden> wrote:
I asked:

> I want to join two arrays to make a bigger array.

Judd Storrs answered:

> I think should [ A B ] work.

Ok, thanks; I missed the space separator. I was using a comma. But, as
you can probably guess, this is just the latest frustration with a more
complex task. Here's an outline of the whole problem.

Given a CSV file with 15 columns, I want to create a new CSV file with
the first column identical to the first column of the existing file and
a single additional column equal to a convolution of one of the other
columns of the existing file. Diagrammatically,

 FileA = Time, H2,H3,H4,..       FileB = Time, Hx
         00:05,01,02,03,..  ==>          00:05,11
         00:10,04,05,06,..               00:10,12
         00:15,07,08,09,..               00:15,13

(The numbers aren't real, just made up for this example. But the first
column is a time of day string, not a simple number. It actually
contains a date as well.)

I can read in FileA with << A = csv2cell ( "FileA" ); >> and extract
just the first column with << T = A ( :, 1 ); >>. I can read it in again
with << B = dlmread ( "FileA", "," ); >> and perform my convolution on
column 2 like this,

 f = # some formula;
 r = rows ( B );
 C1 = conv ( B(2:r,2), f );
 C2 = rot90 ( C1 );

Now I need to join T and C2 to produce a new array, presumably a cell
array which I can write out with cell2csv(). But I also need to add a
heading to the C2 column. When I try << C2 = { "Hx" rot90(C1) }; >>, I
get the aforementioned array of arrays, even using a space rather than a
comma.


_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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