Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Combining series of matrices
Replies: 10   Last Post: Jan 26, 2013 10:05 AM

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: Combining series of matrices
Posted: Jan 22, 2013 10:35 AM

On 1/21/2013 4:12 PM, dpb wrote:
> On 1/20/2013 11:30 AM, Ehsan wrote:
>> "james bejon" wrote in message <kdh908\$g0c\$1@newscl01ah.mathworks.com>...
>>> If you supply some code that generates the relevant data structure,
>>> I'll happily have a go...

>>
> ...
>
> Lum.data=[];

...Previous code elided for brevity to correct a syntax problem of
concatenating a structure w/ an array...
>
> Salt to suit...

Concatenate the L and R arrays then create the structure in the end--

L=[];
R=[];
while date<=end_date
filename=sprintf('SS%s.csv',datestr(date,'yymmdd'));
d=importdata(filename,',',9);
nr=size(d.data(:,2));
time=zeros(nr,1);
time=datenum(d.textdata(10:nr+9,2),'HH:MM:ss');
time=date+time-735235;
d.data=[datevec(time),d.data];
L=d.data(1:2:end,:);
R=d.data(2:2:end,:);
L(L(:,1)==0)=[];
R(R(:,1)==0)=[];
L=[L;L];
R=[R;R];
date=date+1;
end
Lum.data=L;

NB that if there are a large number and/or they are large, this will get
slow as it grows. If you know the sizes a priori you can help by
preallocating a large-enough array and populate it explicitly w/ ranges.
Keeping the full sizes and then collapsing the null entries at the end
before creating the structure may also be faster than doing each first;
I've not tested that w/ any random data to see if can tell any
significant difference.

--

Date Subject Author
1/20/13 Ehsan
1/20/13 dpb
1/20/13 james bejon
1/20/13 Ehsan
1/20/13 james bejon
1/20/13 Ehsan
1/21/13 dpb
1/22/13 dpb
1/22/13 dpb
1/26/13 Ehsan
1/26/13 dpb