COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### how to count the occurence of events cumulatively in Matlab fast?

• Email
• Follow

```Hi all,

I have two questions:

-------------------------------------------
Q1:

Let's say we have an array "x", which is an Nx1 column vector of time
series data, following the order of days...

And we would like to output another Nx1 column vector "y", with "0" or
"1" binary values.

Intially the Nx1 output column vector "y" contains all "0"s.

We would like to count, cumulatively, that in the past "m" days, how
many days the data number is below a threshold "t".

And if the number of below-threshold occurence exceeds "n" days, we
would like to output "1" to the output vector,
i.e. set the corresponding location in "y" to be "1", and all the
following values in "y" are set to "1", until the opposite
situation occurs, i.e. until when the number of days that the data
number in "x" is above the threshold "t" (num of above-threshold
occurence)
exceeds "n" days, then we turn the output back to "0", and all the
following values in "y" are set to "0".

So the number of below-threshold occurence and the number of above-
threshold occurence exceeding "n" days are our switch-on and switch-
off points.

Q2:

The same as Q1, except the switch-on and switch-off points becoem:

the number of consequtive(several days in a row) below-threshold
occurence in the past "m" days

and the number of consequtive(several days in a row) above-threshold
occurence in the past "m" days

exceeding "n" days...

-------------------------------------------

I currently wrote this logic with a bunch of "for" loops and it's
really slow,

and I guess the gurus on this forum may have some experience about how
to do this logic without for loops and pure vector operations.

Thank you!
```
 0
Reply lunamoonmoon (258) 7/28/2010 3:24:08 PM

See related articles to this posting

```On Jul 28, 11:24=A0am, Luna Moon <lunamoonm...@gmail.com> wrote:
> Hi all,
>
> I have two questions:
>
> -------------------------------------------
> Q1:
>
> Let's say we have an array "x", which is an Nx1 column vector of time
> series data, following the order of days...
>
> And we would like to output another Nx1 column vector "y", with "0" or
> "1" binary values.
>
> Intially the Nx1 output column vector "y" contains all "0"s.
>
> We would like to count, cumulatively, that in the past "m" days, how
> many days the data number is below a threshold "t".
>
> And if the number of below-threshold occurence exceeds "n" days, we
> would like to output "1" to the output vector,
> i.e. set the corresponding location in "y" to be "1", and all the
> following values in "y" are set to "1", until the opposite
> situation occurs, i.e. until when the number of days that the data
> number in "x" is above the threshold "t" (num of above-threshold
> occurence)
> exceeds "n" days, then we turn the output back to "0", and all the
> following values in "y" are set to "0".
>
> So the number of below-threshold occurence and the number of above-
> threshold occurence exceeding "n" days are our switch-on and switch-
> off points.
>
> Q2:
>
> The same as Q1, except the switch-on and switch-off points becoem:
>
> the number of consequtive(several days in a row) below-threshold
> occurence in the past "m" days
>
> and the number of consequtive(several days in a row) above-threshold
> occurence in the past "m" days
>
> exceeding "n" days...
>
> -------------------------------------------
>
> I currently wrote this logic with a bunch of "for" loops and it's
> really slow,
>
> and I guess the gurus on this forum may have some experience about how
> to do this logic without for loops and pure vector operations.
>
>
> Thank you!

Anybody?
Thanks a lot!
```
 0

```Your explanation is long and hard to follow.  It would be MUCH clearer what you're doing if you:

1) Provide a small sample of input and what your desired output would be for that input.
2) Provide the code that you say you already have and that is (presumably) working correctly, however slowly.
```
 0

2 Replies
263 Views

Similar Articles

12/10/2013 9:58:58 PM
page loaded in 147192 ms. (0)

Similar Artilces:

fast convolution in Matlab
Does anyone know where I might obtain a Matlab function to perform a fast convolution in Matlab. I have my own but its written in Matlab. I'd like one that was done in C(++), fortran, ect. Speed is an issue. S.M. A convolution in time domain corresponds to a simple product in frequency domain If you are interested to perform convolution in time domain see this implementation, it may be useful for your goal: <http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1093828&objectType=author> Luigi Rosa Stephen McGovern wrote: > > > Does anyone...

Counting
HI, I have dataset as follows data have; id a 1 1 1 0 1 1 2 0 2 1 3 0 3 0 ; data want; id a count1 count0; 1 1 2 2 1 1 3 0 2 ; I want number of '0' s in field ' a' as count0 and '1' s as count1 Plz provide solution? Hi chowdary, You could use PROC FREQ and PROC TRANSPOSE and one or more data steps, but the following is a rather simple solution: DATA Want; SET Have; BY ID; * must already be sorted! ; IF (FIRST.ID) THEN DO; Count0 = 0; Count1 = 0; END; IF (A) THEN Count1+1; * A supposed only 1 or 0 ; ELSE Co...

Event handler fires multiple events after page reload
Hi all, i have a js application with several event handlers which i manage via prototype .bindAsEventListener. On normal page navigation ( link navigation ) i finish all events handlers (onUnload) if a new page should be loaded and everything works fine: All event handlers are finished and the new page works fine. However, if i do a browser "reload" the events a fired twice after it. I did some debugging and i am sure that the onunload functions are called with the browser "reload": But the event handlers seem to exist anyway after it. So what i wanted to know: - Is thi...

Events Function
I am getting the following error message when using ode15 with an event function: ??? SWITCH expression must be a scalar or string constant. Error in ==> funfun\private\odeevents at 32 switch lower(eventFcn) Error in ==> ode15s at 263 [haveEventFcn,eventFcn,eventArgs,valt,teout,yeout,ieout] = ... Error in ==> Systems_6DOF_init at 185 [t,x,te,xe,ie] = ode15s('SystemSimulation', tspan, x0, options); I've basically copied and pasted the "events" function from the ballode example to fit my code. The m file to detect events, is literally 3 lines long just li...

Matlab 2007A
I am using the student version of Matlab the 2007a version. I would like to know is it possible to interface the National Instruments USB 6251 with my version of Matlab. I am aware i will have to purchase the Data Aquistion Tool suite but i would like to know is it possible and what are the steps i must take so as matlab can read a particular channel input from the device. Hi Alan The National Instruments USB-6251has been supported since Data Acquisition Toolbox 2.9 which was released with R2006b so you're all set vis a vis R2007a. Start here to learn about Data Acquisition Toolbox http...

Matlab Integration
I have a function called CalculateE, which determines the electric field given x and y. In another script, I want to integrate this function from x = a to x = b and at a given y. In this script currently I call ETotal = quad(@CalculateE, a, b) to perform the integration in the x-direction. Is there a way using this command that I can pass the (constant) value of y into the function I am integrating? "Kevin Bachovchin" <kbachovc@andrew.cmu.edu.edu> wrote in message <hjdog6\$9oq\$1@fred.mathworks.com>... > I have a function called CalculateE, which determines the e...

VHDL events
Hi, I have just started trying to learn VHDL and I am wondering about the "event" keyword. If I write: process(clock) begin if clock'event and clock = '1' then end if end process; then I step inside the if statement every rising clock edge. If I do the opposite: process(clock) begin if clock'event and clock = '0' then end if end process; then do I step inside every falling clock edge? Also, can I do this: process(clock) begin if clock'event and clock = '0' then elsif clock'event and clock = '1' then end if...

key event
Hi, I am using org.netbeans.swing.outline package for tree table. I want that when I press enter on a cell in the table it will be the same as I press double click on the sell-> text box will open in the sell. How can i do it? Thanks . ...

censoring when you have events
Hi, I have a longitidinal dataset with two surgeries (right and left). However I want to look at first surgery (event) which will be either right or left. the data looks something likes this: ID visit sxr sxl 1 1 0 0 1 2 0 1 1 3 1 0 1 4 0 0 2 1 0 0 2 2 0 1 2 3 1 0 3 1 1 0 3 2 0 1 3 3 0 0 How can I create a new variable that selects the first occurence of surgery either left or right for each subject. It may look lik...

Execution Count
Hi: I am interested in extracting execution counts of basic blocks from SPEC2000 bench mark. It can be done using profiling. Is there any flag in gcc which does this thing for me and dump the information in a file? or any other compiler which has a feature which will help me in doing that. Thanks Abid ...

Implementing a Phaser in MATLAB
I saw a diagram on wiki and would like to implement it in MATLAB but have no clue on how to do it... Can someone help me out please? I'm trying to write the difference equation but somehow not able to start with it... http://en.wikipedia.org/wiki/Phaser_(effect) Thanks On Dec 7, 10:52 pm, Legend <rahul...@gmail.com> wrote: > I saw a diagram on wiki and would like to implement it in MATLAB but > have no clue on how to do it... Can someone help me out please? I'm > trying to write the difference equation but somehow not able to start > with it... > > http://en....

Matlab Mobile and graphs
Is there a way to show graphs plotted on my desktop on my tablet? Currently the only way to get graphs on my tablet is by starting the plot command on the tablet itself. I would be useful if one could plot directly to the screen of the tablet and even manipulate graphs from the tablet so they get updated on the desktop. "Mehmet Aksakal" <nospam.nowhere@spamdamelam.org> wrote in message <ka8hah\$kem\$1@newscl01ah.mathworks.com>... > Is there a way to show graphs plotted on my desktop on my tablet? Currently the only way to get graphs on my tablet is by starting the plo...

Matlab on mosix cluster
Has anyone had succes running matlab on a mosix cluster ? What is needed (toolkits ?) Regards Jesper Jesper wrote: > Has anyone had succes running matlab on a mosix cluster ? > What is needed (toolkits ?) > > Regards > Jesper > > Hi, I'm not sure about what's a MOSIX cluster is. IIRC, it implies changes to the Linux kernel to provide single-system-image in the sense of common-PID space (when you ps -ax you get unique PIDs from all over the cluster?) and it also provides for transparent process migration? Don't know. I'm not sure, but if you can ru...

Connection to a matlab Server
At university, there is a machine, much more powerful than my pc, with matlab/network license installed. How I can manage to connect remotely to this matlab server? I found no connection options in 'regular' matlab installed on my pc... Thanks. ...

assigning events dynamically
dear esteemed javascript gurus. consider the following fragment: var buttons = document.getElementById("tr_Toolbar").getElementsByTagName("button"); for (var i=0; i<buttons.length; i++) { var button = buttons[i]; button.onmouseup = function() { mouseup(button.id); return false; } } during this loop, button.id is correctly returned as the id of the button being processed, and all the buttons are assigned a mouseup event. however, whichever button is clicked, the mouseup function is always invoked with the id of the last button in the list. I guess it's because t...

matlab #2 410884
hello every body Now I have some problems .I need all of you help me. Can you tell me " how to set label to the middle of image by using Matlab". thank advance ! On 10-11-03 02:09 PM, kompheak koh wrote: > hello every body Now I have some problems .I need all of you help me. > Can you tell me " how to set label to the middle of image by using Matlab". > > thank advance ! get() the XData and YData properties of the image object. Each of them will be a two element vector. Average those two elements each, to obtain the X and Y coordinate of the cent...

matlab fuction help
hi again &#305; prepared a gui and works fine. &#305; inserted two button firsst start second stop for process the problem &#305; started the process then when &#305; want to stop &#305; cant take values because start function doesnt write values to workspace so stop function couldnt take. so how can &#305; solve this problem help pls thanks for attention Dear Ali! > &#305; inserted two button firsst start > second stop for process > > the problem &#305; started the process then when &#305; want to stop &#305; cant take values beca...

Matlab and graphical outputs
Yet again, a student just came to me asking for advice about generating output files for Matlab graphics, as she was having problems. I gave the usual schtick about print -deps -r150 ..., and as usual pointed out that I've had more trouble generating dependable WYSIWYG output files from Matlab than from any other application I've ever used. Despite fine books by Marchand, Hanselman, and such, as well as nearly a decade of participation here, I've never been pointed to a procedure that ALWAYS works. There will always be those instances of fuzzy text, mysterious lines that do...

Java versions in Matlab
Hi all, I am collating information about the different Java versions pre-bundled with Matlab on different platforms and Matlab releases. For example, I know about the following Matlab releases on Windows: - Release 12 (6.0) &#8211; Java 1.1.8 - Release 12.1 (6.1) &#8211; Java 1.3.0 - Release 13 (6.5) &#8211; Java 1.3.1 - Release 14 (7.0) &#8211; Java 1.4.2 - Release 14 SP 2 (7.0.4) &#8211; Java 1.5.0 - R2007b (7.5) &#8211; Java 1.6.0 - R2010a (7.10) &#8211; Java 1.6.0_12-b04 I would appreciate your help to provide similar information about non-Wind...

select count in perl
Hi, I would like to know how I could move the select count I am doing in mysql on the perl side: mysql -hhost -uanonymous mydb -e "select count(status), status from table group by status order by null" to instead something like: mysql -hhost -uanonymous mydb -e "select status from table order by null" | perl "give me the count numbers" Anyone? avilella@gmail.com wrote: > Hi, > > I would like to know how I could move the select count I am doing in > mysql on the perl side: > > mysql -hhost -uanonymous mydb -e "select count(status), st...