Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
find problem

Subject: find problem

From: Jonathan

Date: 1 Nov, 2011 23:20:20

Message: 1 of 7

Hi,

I have the following problem. I have two matrices of unequal size: A(14820,2) and B(14677,2), with each matrix characterized by time and peak tide elevation. What I'm trying to do is eliminate those extra peak tides in A (i.e. 143 extra peaks) so that I'm left with a matrix of equal size to B (basically the peak detection algorithm I have detected a bunch of extra peaks in tide A compared with tide B). What I was hoping to do is find those times in A that approximately equal B (allowing for initially +/-1 hour tolerance), however, matlab requires the two matrices to be the same dimension. I'm drawing a blank as to how else I could do this. Any suggestions would be much appreciated?

Thanks
Jon

Subject: find problem

From: dpb

Date: 1 Nov, 2011 23:26:30

Message: 2 of 7

On 11/1/2011 6:20 PM, Jonathan wrote:
> Hi,
>
> I have the following problem. I have two matrices of unequal size:
> A(14820,2) and B(14677,2), with each matrix characterized by time and
> peak tide elevation. What I'm trying to do is eliminate those extra peak
> tides in A (i.e. 143 extra peaks) so that I'm left with a matrix of
> equal size to B (basically the peak detection algorithm I have detected
> a bunch of extra peaks in tide A compared with tide B). What I was
> hoping to do is find those times in A that approximately equal B
> (allowing for initially +/-1 hour tolerance), however, matlab requires
> the two matrices to be the same dimension. I'm drawing a blank as to how
> else I could do this. Any suggestions would be much appreciated?

OTOMH, for that I can only think of working through the two time series
sequentially comparing the current time in the master list w/ that in
the second. I would presume that they're ordered and over the same
total time from the problem description and so it would only be a couple
or three points at each point to compare to before you know you can go
to the next in the first. That won't take long for relatively short
vectors of the sizes given.

--

Subject: find problem

From: TideMan

Date: 2 Nov, 2011 00:49:21

Message: 3 of 7

On Nov 2, 12:26 pm, dpb <n...@non.net> wrote:
> On 11/1/2011 6:20 PM, Jonathan wrote:
>
> > Hi,
>
> > I have the following problem. I have two matrices of unequal size:
> > A(14820,2) and B(14677,2), with each matrix characterized by time and
> > peak tide elevation. What I'm trying to do is eliminate those extra peak
> > tides in A (i.e. 143 extra peaks) so that I'm left with a matrix of
> > equal size to B (basically the peak detection algorithm I have detected
> > a bunch of extra peaks in tide A compared with tide B). What I was
> > hoping to do is find those times in A that approximately equal B
> > (allowing for initially +/-1 hour tolerance), however, matlab requires
> > the two matrices to be the same dimension. I'm drawing a blank as to how
> > else I could do this. Any suggestions would be much appreciated?
>
> OTOMH, for that I can only think of working through the two time series
> sequentially comparing the current time in the master list w/ that in
> the second.  I would presume that they're ordered and over the same
> total time from the problem description and so it would only be a couple
> or three points at each point to compare to before you know you can go
> to the next in the first.  That won't take long for relatively short
> vectors of the sizes given.
>
> --

Another way, assuming you have semidiurnal tides is to calculate an
index of high tides:
dt=12.42/24; % Assuming your times are in Matlab days
indx=round((B(:,1)-A(1,1))/dt);
Now formulate C with the times from A and NaN in the heights:
C=[A(:,1) NaN(1480,1)];
And insert the times and heights from B
C(indx,:)=B;

Note that the times for the missing data will be from A.

Subject: find problem

From: Jonathan

Date: 2 Nov, 2011 20:47:11

Message: 4 of 7

TideMan <mulgor@gmail.com> wrote in message <58b835fd-7056-4fa3-951f-6ff618aef851@j20g2000vby.googlegroups.com>...
> On Nov 2, 12:26 pm, dpb <n...@non.net> wrote:
> > On 11/1/2011 6:20 PM, Jonathan wrote:
> >
> > > Hi,
> >
> > > I have the following problem. I have two matrices of unequal size:
> > > A(14820,2) and B(14677,2), with each matrix characterized by time and
> > > peak tide elevation. What I'm trying to do is eliminate those extra peak
> > > tides in A (i.e. 143 extra peaks) so that I'm left with a matrix of
> > > equal size to B (basically the peak detection algorithm I have detected
> > > a bunch of extra peaks in tide A compared with tide B). What I was
> > > hoping to do is find those times in A that approximately equal B
> > > (allowing for initially +/-1 hour tolerance), however, matlab requires
> > > the two matrices to be the same dimension. I'm drawing a blank as to how
> > > else I could do this. Any suggestions would be much appreciated?
> >
> > OTOMH, for that I can only think of working through the two time series
> > sequentially comparing the current time in the master list w/ that in
> > the second.  I would presume that they're ordered and over the same
> > total time from the problem description and so it would only be a couple
> > or three points at each point to compare to before you know you can go
> > to the next in the first.  That won't take long for relatively short
> > vectors of the sizes given.
> >
> > --
>
> Another way, assuming you have semidiurnal tides is to calculate an
> index of high tides:
> dt=12.42/24; % Assuming your times are in Matlab days
> indx=round((B(:,1)-A(1,1))/dt);
> Now formulate C with the times from A and NaN in the heights:
> C=[A(:,1) NaN(1480,1)];
> And insert the times and heights from B
> C(indx,:)=B;
>
> Note that the times for the missing data will be from A.
>
Thanks for the help. Yes the tides are indeed semidiurnal.
I tried these suggestions and matlab indicated an error with the last line "??? Subscript indices must either be real positive integers or logicals." Thoughts on this error message.

Thanks

Subject: find problem

From: dpb

Date: 2 Nov, 2011 21:23:45

Message: 5 of 7

On 11/2/2011 3:47 PM, Jonathan wrote:
> TideMan <mulgor@gmail.com> wrote in message
> <58b835fd-7056-4fa3-951f-6ff618aef851@j20g2000vby.googlegroups.com>...
...

>> dt=12.42/24; % Assuming your times are in Matlab days
>> indx=round((B(:,1)-A(1,1))/dt);
>> Now formulate C with the times from A and NaN in the heights:
>> C=[A(:,1) NaN(1480,1)];
>> And insert the times and heights from B
>> C(indx,:)=B;
...

> Thanks for the help. Yes the tides are indeed semidiurnal. I tried these
> suggestions and matlab indicated an error with the last line "???
> Subscript indices must either be real positive integers or logicals."
> Thoughts on this error message.
...

Look and the values of indx; I'm guessing you'll have zero altho
depending on B and A values, <0 is also a possibility since there's no
checking done.

--

Subject: find problem

From: TideMan

Date: 2 Nov, 2011 21:36:21

Message: 6 of 7

On Nov 3, 10:23 am, dpb <n...@non.net> wrote:
> On 11/2/2011 3:47 PM, Jonathan wrote:> TideMan <mul...@gmail.com> wrote in message
> > <58b835fd-7056-4fa3-951f-6ff618aef...@j20g2000vby.googlegroups.com>...
>
> ...
>
> >> dt=12.42/24; % Assuming your times are in Matlab days
> >> indx=round((B(:,1)-A(1,1))/dt);
> >> Now formulate C with the times from A and NaN in the heights:
> >> C=[A(:,1) NaN(1480,1)];
> >> And insert the times and heights from B
> >> C(indx,:)=B;
>
> ...
>
> > Thanks for the help. Yes the tides are indeed semidiurnal. I tried these
> > suggestions and matlab indicated an error with the last line "???
> > Subscript indices must either be real positive integers or logicals."
> > Thoughts on this error message.
>
> ...
>
> Look and the values of indx; I'm guessing you'll have zero altho
> depending on B and A values, <0 is also a possibility since there's no
> checking done.
>
> --

Ah, yes of course, it should be:
indx=round((B(:,1)-A(1,1))/dt) + 1;

But you need to check these things out yourself.
It would have been blindingly obvious if you had printed indx out.
Most of the time I'm perfect, but in this case I was a little short of
that.

Subject: find problem

From: Jonathan

Date: 3 Nov, 2011 15:26:27

Message: 7 of 7

TideMan <mulgor@gmail.com> wrote in message <39cff776-fa8f-495b-8859-bcb844ec14b2@o5g2000yqa.googlegroups.com>...
> On Nov 3, 10:23 am, dpb <n...@non.net> wrote:
> > On 11/2/2011 3:47 PM, Jonathan wrote:> TideMan <mul...@gmail.com> wrote in message
> > > <58b835fd-7056-4fa3-951f-6ff618aef...@j20g2000vby.googlegroups.com>...
> >
> > ...
> >
> > >> dt=12.42/24; % Assuming your times are in Matlab days
> > >> indx=round((B(:,1)-A(1,1))/dt);
> > >> Now formulate C with the times from A and NaN in the heights:
> > >> C=[A(:,1) NaN(1480,1)];
> > >> And insert the times and heights from B
> > >> C(indx,:)=B;
> >
> > ...
> >
> > > Thanks for the help. Yes the tides are indeed semidiurnal. I tried these
> > > suggestions and matlab indicated an error with the last line "???
> > > Subscript indices must either be real positive integers or logicals."
> > > Thoughts on this error message.
> >
> > ...
> >
> > Look and the values of indx; I'm guessing you'll have zero altho
> > depending on B and A values, <0 is also a possibility since there's no
> > checking done.
> >
> > --
>
> Ah, yes of course, it should be:
> indx=round((B(:,1)-A(1,1))/dt) + 1;
>
> But you need to check these things out yourself.
> It would have been blindingly obvious if you had printed indx out.
> Most of the time I'm perfect, but in this case I was a little short of
> that.

Thank you for your help. This works.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us