File Exchange

image thumbnail

Rainflow Counting Algorithm

version (39 KB) by Adam Nieslony
Very fast rainflow cycle counting for MATLAB


Updated 04 Apr 2010

View License

The rainflow algorithm code has been prepared according to the ASTM standard (Standard practices for cycle counting in fatigue analysis) and optimized considering the calculation time.

Cite As

Adam Nieslony (2020). Rainflow Counting Algorithm (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (214)

Paul Soskin


Chenhui Dai




Professor Adam Nieslony,

Thank you for putting this code in matlab for everyone to use.

Balajee Ananthasayanam


Is it possible to specify the width of Bin Edges when calculating the rainflow cycle counts matrix c = rainflow(x) ?

After computing the cycle counts for the data, using the command: [c,hist,edges,rmm,idx] = rainflow(Y) , I plot a histogram of cycle counts as a function of stress range, using the command: histogram('BinEdges',edges','BinCounts',sum(hist,2)) , as indicated in the example of the Matlab Documentation
It seems that the 'Bin Edges' are assigned an arbitrary width value. Instead, I would like to assign a specific width value to the Bin Edges, while ploting the histogram of the cycle counts, resulting from the cycle counts matrix 'c = rainflow(x)'.

How can we specify the width of Bin Edges when calculating the rainflow cycle counts matrix 'c = rainflow(x)' ?

Maaz Rao

The RFPDFD file of the code is not provided it is mentioned in 4th last line of rainflow.m but not provided kindly share the required file

Hi, I am new to MATLAB but believe use of this algorithm would be useful for my work. Could you perhaps provide an example of how to use the tool? I understand this may sound trivial but any advice given will be appreciated.

@Md Alamgir Hossain
Dear Hossain iam currently working on battery degradation as well. can you please share your rainflow counting algorithm?


Hi Mr Adam Nieslony,
can you give me an example that can make me understand more how can i use 'Rainflow Counting Algorithm' and how can i exploit results (number of cycles, amplitude,period...)

@Jan-Pascal Gruhler
Dear Gruhler,
I am currently working on the degradation cost of the battery as of you. May I ask you to provide me your Rainflow algorithm for the cycles cost you determined? email:
Thanks in advance.

hello i have some query if someone could please provide some insight to it

Do we need to cater for stress ratio in our load spectra which we obtain after application of rainflow algorithm. if yes then how do we incorporate them. because by the use of rain-flow counting we a summary of cycle amplitude and number of cycles. we cannot see what the stress ratio of each cycle. ( by stress i mean min to max value of each cycle)


how do i use my own time Signal in this calculation (rfdemo2)?

One small observation: The matlab by default algorithm gives peak to peak value of cycle, where this one gives the amplitude.

thank you sebastian laechele for your valuable inputs. i wanted to ask one more thing form you. if we apply rainflow counting to a load vs time history. we will get a matrix in which cycle counts are represented against the range and mean values of that respective cycle. if we want to do a fatigue life prediction. which value will we be applying on our model to get the stress at that corresponding load. will it be the range, or the mean or the amplitude( which will be the half of range ).

Your work was excellent sir, very useful piece of software. I would like to make an observation: it appears to me that the rainflow.c file would not be slow at all if it were written as a matlab function. I made some minor adjustments to your .c file in order to create an .m file. It seems actually (almost) as fast as the .mex file the few times I tried it. A useful note: without running the matlab profiler the 2 functions seem to take almost the same time, whereas with the profiler on the matlab function is slower, because a mex file cannot be profiled (as far as I know).
Here's the code, if it could be of any use:

function R = rainflow(ext,extt)

% RAINFLOW $ Revision: 1.1 $ */
% by Adam Nieslony, 2009 */

% RAINFLOW cycle counting.
% RAINFLOW counting function allows you to extract
% cycle from random loading.
% rf = RAINFLOW(ext)
% rf = RAINFLOW(ext, dt)
% rf = RAINFLOW(ext, extt)

% rf - rainflow cycles: matrix 3xn or 5xn dependend on input,
% rf(1,:) Cycles amplitude,
% rf(2,:) Cycles mean value,
% rf(3,:) Number of cycles (0.5 or 1.0),
% rf(4,:) Begining time (when input includes dt or extt data),
% rf(5,:) Cycle period (when input includes dt or extt data),
% ext - signal points, vector nx1, ONLY TURNING POINTS!,
% dt - sampling time, positive number, when the turning points
% spaced equally,
% extt - signal time, vector nx1, exact time of occurrence of turning points.

% Copyright (c) 1999-2002 by Adam Nieslony,
% MEX function.

% ++++++++++ BEGIN RF3 [ampl ampl_mean nr_of_cycle] */
% ++++++++++ Rain flow without time analysis */

j = 0;
if nargin==1
for index=1:tot_num
while ( (j >= 3) && (abs(ext(j-1)-ext(j-2)) <= abs(ext(j)-ext(j-1))) )
ampl=abs( (ext(j-1)-ext(j-2))/2 );

case 1
case 2
case 3
if (ampl > 0)

if (ampl > 0)



for index=1:j
if ampl > 0
% ++++++++++ END RF3 */

if length(extt)>1


for index=1:tot_num
while ( (j >= 3) && (abs(ext(j-1)-ext(j-2)) <= abs(ext(j)-ext(j-1))) )
ampl=abs( (ext(j-1)-ext(j-2))/2 );

case 1
case 2
case 3
if (ampl > 0)

if (ampl > 0)


for index=1:j
if ampl > 0

% ++++++++++ END RF5 */





Dear Mr Nielsony,

For my internship, I am trying to apply the rainflow algorithm on a large data set with very heteregeneous amplitude. Because of that, it seems that the algorithm only considers one given load range as evidenced by the rf histogram which shows only one class.

In other terms, there is kind of thersholding which makes most of the peaks neglected. I confirmed that by trying the algorithm on a more restricted dataset and the results were this time more relevant.

The algorithm already sums up cycles of identical range. Maybe your ranges have a slight variation and are therefore counted individually?
Maybe you want to aggregate cycles with similar ranges.
Not sure how to do that with a simple command, maybe the hist/histogram function returns indices of elements inside a bin?

About you second question: I could not find a way to define the bin size or the number of bins. Maybe check the contents of Adams function and do a hard coded modification...

with regards to the help that you provided . i want to thank you. it was very helpfull.
but what i am looking for is the total number of counts against each amplitude or range.
like if i have twenty 0.5 cycles mentioned against range of 0.01 in 20 different rows. i want a single row answer of 10 cycles against range of 0.01 and so on for every different range.
basically i want to use this algortihm on my load vs time signal and extracts cycles and then use miner damage rule to predict remaining life. so i am interested in a table of number of total cycle counts and its corresponding amplitude. and so on for every amplitude

i also want to ask another questions that how the bin size is selected in this algorithm? and is there a default value.
and will the total number of cycles be effected by the number of bins. will the cycle count increase or decrease with the increase in the bins number.
is there any way to see the number of bins and to change them if required?

Hello Hussain,
I hope I understand you correctly: you want to accumulate the cycle counts starting with largest value to get a load collective?
We did it this way:
% create table with cycle range and mean values
cycles = rainflow(transient_data);
% sort by range
[~,idx_sort] = sort(cycles(:,2), 'descend');
% calculate cummulative sum of cycles and store in new column 6
cycles(idx_sort,6) = cumsum(cycles(idx_sort,1));
load_collective = cycles(idx_sort,:);
plot(load_collective(:,6), load_collective(:,2));

Keep in mind that the range is twice the amplitude...

Hi Mr Adam
i want to ask you that when we apply this algorithm we get a table of cycle count (0.5 or 1) , cycle amplitude and cycle mean value. i want to have a summary of total counts and its corresponding amplitudes. which i am at the moment not been able to extract. basically i want the cycle count and amplitude so that i could use those values and apply on my structural model for conversion of load values into stress values. can you please provide some help in this regard.

Dear Cindy Marquardt,
Please, write me more details about the problem and I will try to help you.
Adam Niesłony

Because the last entry od binwidth is zero, adding half of it to the last middle of the highest cluster doesn't set yy(end) to the upper boundary. So every entry that lies over the middlepoint isn't count.

Rhys Evans

Wesley Lang

Rhys Evans

Hy Mr. Nieslony. I would like to use the code, but since I'm a starter in Matlab with only basic knowledges,
I have difficulties to use it. Could you please give me a quick instruction how to proceed?
1. Where to insert the input values (I have the junction temperatures of a sc power module after an operation as a vector)
2. Which file to use: I can't open the mex file and c file seem to be a different language. It seems like
that I have to debug the c file to m file. How is it done?
3. The crucial outputs for my analysis are the peak temperatures and the temperature swings (ΔT), which correspond to that peak. Can I get these two information from your code?

I'm using the mac and the newest version of Matlab (R2018a).
Thank you so much for your support in advance!

ping zhang


It works perfectly!!

yz Li


Lesson2/3 is necessary?

Jax Huang

Very useful, thank you!




I have a long vector of peaks and valleys (124427 data points long). If I run the rainflow along the whole vector, it does not capture the amplitude of the minimum point to the maximum. However, if I take a small segment starting at the minimum and ending at the maximum, it does calculate that maximum amplitude. Interestingly, if I compare the magnitudes of the cycles of the whole vector vs the truncated vector, every cycle value is the same except for the last maximum cycle. Is there a reason for this to be occurring? I have had great success with this code, this one situation is stumping me, however.

pierre jin


Hello Mr. Nieslony,

I just would like to know if your calculations of the cycles were done according a standard, or a paper from which I could get the theoretical algorithm and calculations. Personnally, I am using the 4-points Rainflow method according to the French NF standard A03-406, which requires a peaks-valley pre-treatment of the data, and two conditions to fulfill to count a cycle, the second being fabs( a[j-1]-a[j-2]) <= fabs( a[j-3] - a[j-2] ). I did not see these two conditions in your algorithm. Do you have a paper or a thesis or a standard or else to justify the calculations ? I just would like to see if the results are the same, or if the method you are using presents trustwworthy results or mathematical validation.

Thank you very much


Hans Jane

Yeah, that's right. But if the programmer is a fresher like me, have never debugged matlab with VC before, he/she will meet the problem I have meeted too, so I suggest you to give more detailed explanation in the zip or convert C to .m, thank you:)

Adam Nieslony

Hans Jane, apologies accepted :-)
One note again: '... and two lines of crucial code should be included in the"rfdemo1.m" or "rfdemo2.m" starts,...' NO, THIS IS NOT CORRECT! If you write this two lines then each time when you run this m-files you will setup the MEX compiler and compile the C++ file. This is not necessary (we should do that only one time) and from the programmer point of view incorect.

Hans Jane

OK,Adam, I'm really sorry for the low rating, and I have debugged the program this weekend.
The program need to debug with VC, the users need to install Visual Studio(recommed VC2010+) and .NET framework (recommend .NET framework 4.5+)first, and two lines of crucial code should be included in the"rfdemo1.m" or "rfdemo2.m" starts, that IS
mex -setup C++
mex rainflow.c
be sorry again for the inappropriate comment .

Adam Nieslony

In reference to the comment of Hans Jane from 18 May 2017:
1. Please, go to the basic lesson about Matlab and read carefully the part about MEX function.
2. Download the ZIP file with all toolbox files.
3. Do not try to run old help files, it doesn't make sense.
4. Trust other people who write that everything is OK and search for mistakes first on your side.
5. Do not rate something what you are not understand :-)
Adam Niesłony, author of rainflow

Hans Jane

What's wrong with the main program"rainflow.m", all of them is annotate, is there any usable code????

Can anyone help me how to bring and run this code in Python?
Thanks in advance

Xi Chen

Hisham PC

ls it right to multiply the cycles amplitudes, rf(1,:) with 2 to get stress ranges in order to use the S-N curves to find N values.

Hisham PC

plz reply

Hisham PC

@ Lee Zoro: I stumbled over the issue with the amplitude in the first place, too. The result of of rainflow(ext) is correct though.

Please note the difference between amplitude and peak-to-peak values. What you are looking after is the peak-to-peak value of certain cycles (0.10 0.20). The amplitude of those cycles is (0.05 0.10) and was calculated correctly by rainflow(ext).

Adam, great toolbox. Thanks for that. I used it for cycle counting in the field of lifetime prediction for LiIon-Batteries.

Yun Huang

very good resource!

Dear Olga Ibragimova, look at the comment from 13 Mar 2013 Jeppe Otten for the 'macbook' solution. I am MS Windows user :-(

Doesn't work at my macbook :(

when putting rfdemo1 it says:

Attempt to execute SCRIPT rainflow as a function:

Error in rfdemo1 (line 35)

There's something it doesn't like, but I can't really understand.

Amazing and it was easy to port it to Python using Cython

Lee Zoro

Hello,I used the following code:
sig=[0.2 0.4 0.3 0.4];
and the result(rf) is:
0.05 0.10 (cycles amplitude)
0.35 0.30 (cycles mean value)
1 0.50 (number of cycles)
It seems wrong, especially in the first row.
It should be :
0.10 0.20 (cycles amplitude)
isn't it?

Lee Zoro


Great file.


Praveen K R

Can I use this for counting cycles in multiaxial fatigue?

Udit Sood

Hello Adam,
This is an excellent code. Thanks for the share. It works pretty good and shows desired results.
Best Regards

Naval architect.

Eric Kappel

In Matlab R2016b, when running:

>> rfdemo1

I get the following error message:

Attempt to execute SCRIPT rainflow as a function:

Error in rfdemo1 (line 35)

When examining the rainflow.m file it does not contain matlab commands that perform a task.
What am i doing wrong?

P.S. I did add the directory containing the rainflow-scrpts to my path an do have an X-code c-compiler available.

Kind regards,

Eric Kappel

In my model I have used variable modal strain time history generated on mode frequencies.

I have counted strain amplitude and means against each other in fatigue cycles,

And I have assessed fatigue damage using fatigue endurance limit which was 10^6 cycles for my spec, and correpondimng strain enurance level which I have calculated from hooke’s law , for ealstci structure.

But all mu assessment based on modal strain amplitude I have calculated using rainflow algorithm in matlab.

Any comment on this ?

Many thanks,

Best regards,


Hi Adam,
I was wondering whether the package works under MATLAB v6.5.2 r13? I've tried running sig2ext and it worked but neither of the demos does. It always gives me an error message: "??? Attempt to execute SCRIPT rainflow as a function." when running just the rf=rainflow(tp) of the "LESSON 2" of the index.html. When running the rfdemo1 it results in this: "Error in ==> C:\Users\LADA\Documents\MATLAB\RAINFLOW\rfdemo1.m
On line 35 ==> a=rainflow(ext,1);"
Could you guide me a bit please?

Hi Ray,
Without going into details the 5 dimensional matrix is for extracting the time occurrence and duration of each counted cycle and half cycle. This is not the place for discussion so please send me a message to my e-mail account a.nieslony (at)


Hi Adam (and others),
First of all thanks for sharing this!
I was wondering if impulsive loading is taken into consideration in this code since it collects peak time and period in the 5 dimension matrix. Traditionally only mean value and amplitude is taken into consideration in rainflow algorithm. Thanks.


jvn karthik

Hey, I need help to use the rainflow counting algorithm to convert a given set of forces data to a single fatigue load value. The data needs to be imported from excel. How do I go about doing the same?

Adam Nieslony

Thanks Tom for providing information about how to run rainflow on OSX. I am typical Windows user. See also comment from 13 Mar 2013 by Jeppe Otten.




As stated under 'other requirements'
mexmaci64 is not provided in in the .zip.

To compile the source code for OS X follow the instructions given in the accepted answer

Since MATLAB R2015b does not detect Xcode 7.0 by default see (if needed) the accepted answer in



Hi Adam (and others)

Is the a compiler for OSX (vers. 10.11.4 or later) or perhaps some other confirmed method (to make in run on mentioned OS) in the pipeline?


When I used the function rfmartix the output is number of cycles but I want to see the corresponding amplitude and mean values, kindly help plz.

- Kumar

When I used the function rfmartix the output is number of cycles but I want to see the corresponding amplitude and mean values, kindly help plz.

- Kumar

Todd Daniel

It appears the output histogram uses the hist function (rather than histogram) which uses bin centers rather than bin edges. Any guidance on modifying the code to use the histogram function so the output counts are provided using bin edges rather than centers?

Sadaqat ALI

Hello, Everybody. I want to Use Rainflow algorithm for Cycle counting of Battery.I have just SOC in %.
Anyone Help me,it would be Nice.
Thank you

Hi. Congratulations for the code. Wonderfull.
I have tryed to run a simple example from the ASTM E1049 and it gave me different results from the ones in this standard. I might have missed some step to make it work properly. Please advise

The vector of point is [-2 1 -3 5 -1 3 -4 4 -2]


qin bin

thank U

I would like to thank you sincerely for this very fast and useful function.

Pavan Naik

Mr Adam. wonderful ! works perfectly!

I just wanted to ask does anyone of you know how to get the Rainflow filtering and discretization filter before Rainflow count? Does anyone have the code for the same?


I'd suggest you to process your information first, transforming your data to a single matrix, or even adding the results of the multiple cycle counts after using the algorithm.


Thank you for this great tool! But one thing i couldn't figure out so far: I want to add the matrices of multiple sets of data (not multiaxial). Could you (or someone else) please explain me, how to get the same size of matrices? I guess the range is calculated by min/max value of each dataset, can i set it to a fixed value somewhere?

Many thanks in advance.
best regards


First of all thanks for sharing this!

The MEX file is very fast, so fast even that the time-bottleneck is the sig2ext script. Could you please also include a Mex-version of it since it might be (a lot) faster than the .m file ?

Hi,Can anyone tell me how to run the rainflow.c code in matlab?!!! because rainflow.m is empty


I found the first raw of the result from "rainflow" is not the value of stress range, but the value of alternating stress, which is the half of the value of stress range, right?
I think the code should clarify this point, because it may lead the final S-N be incorrect!


Hello everyone,

Matlab crashes when I try to run the script underneath. Does anyone else have the same experience with matlab crashing when using rfdemo2? If anyone knows a solution, I would be very grateful.

KR, Ralph


for t=0:timestep:endtime;


Chudong Qin



hey sear Nieslony
can you help me please to calculate spectral moments in matlab, in order to calculate lifetime theoritically and compare it to rainflow results obtained through your code
thanks a lot sear


Dear, Adam Nieslony
Thank you for writing this matlab file, I am finding it invaluable.


Dear Adam Nieslony
How can I access to win 32 package ?
Best regards

Hi All,

Do you why I get "RAINFLOW: To many input arguments."

I am using 4 arguments

cycles = rainflow(double(peaks), abs( double(lmf)), double(Fatigue.ChanInfo(iCh).LUlt), double(Fatigue.UCMult))';

Hi Abhinav,

Mlife (NREL) uses this function to do fatigue analysis (for wind turbines). if you look at the source code, you might understand how to use it.




I am not able to use this.

I am new to Matlab, can anyone help and let me know how to use this for the set of my data or any data for that matter.




I'm running the tool, and it works very well! Thank you!

But why you describe the cycles with Amplitudes and not Range? Is it correct, to multibly the amplitude by 2 at the end to get the range?

(2*mx) to get the
associated range?

Jeppe Otten

If you are running MatLAB R2012b on a Macbook you can follow the link below in order to use the rainflow.c script:

It will guide you how to install Xcode, patch it and then you are ready to compile your mex file for Matlab by writing this in your command window:

mex rainflow.c

Jeppe Otten

I'm currently running MatLAB R2012b on my Macbook Pro, but I'm having trouble running the script. Is there a rainflow.mexOSX? When I'm running rfdemo1.m it gives me this error:

Undefined function 'rainflow' for input arguments of type 'double'.

Error in rfdemo1 (line 35)



Can anyone explain why the ampl is divided by 2 in rf3 in rainflow.c
"ampl=fabs( (a[j-1]-a[j-2])/2 );"


The function is great.
Btw I've got a question: trying to cross-check results coming from your function and those from another software on the same time series, leads to different rfc. Within your function, half cycles are untreated (I mean being rounded up/down); the mismatch with the other software is located exactly there. Do you know any method to further process half cycles?

Dear Adam,

I am applying this algorithm to a list of State of Charge (in %) of a battery which ranges from 0% to 100%. I think applying this algorithm should return the number of cycles (Y axis) for each range of SOC values (from 0% 5%, then from 5% to 10% and so on) but I am getting really big values for the amplitude (from 0 to 4,000).

Could you please explain if it is possible to get ranges or it just finds mean values and amplitudes?


is there any illustration for using this code, i have mat include for max and min strain for each cycle. can use this code for counting depending on this information and how?



Think I this function can be very helpfull. But I have a question.

I can't se how the discretisation of the level (y-axis) is control and what is the threshold? And is it possible to controlled these?


Dear Adam,

Thank you for your advice, I got the results I wanted from rfdemo1. But I don't know how to get similar results like 'amplitude, mean, number of cycles (cycle or half cycle), begin time of extracted cycle or half cycle, period of a cycle' using rfdemo2. I need to input a lot of data and get the results like list in rfdemo1 using input data like vibrations. Thank you a lot.

Best regards

Jay Park


it was wrong......


Fanally, I found it.


dear Adam,

hi~ I started to study MATLAB just before. I got a problem that I can't input a data to your algorithm. Can you give me an example with inputing some numbers?

Thank you

Jay Park


dear Adam
thank you for your sharing, and there is a question that how can I get the "cycle_begin_time, cycle_period_time" in the "rainflow.c". And how can I make a 'rfhist' input, the format of 'rfhist'.

dear Adam,
I have a small question. I am currently working on a suspension model made in solidworks and i have translated it to simmechanics.i need to calculate the amount of fatigue present .i have been given a load cycle vs time and want to implement it .How can i do it here?


This function is great, the only bad point is the lack of a message, when overflow or underflow occour

Best regards



Dear Adam,

at the end works fine. I didn't read properly the help file to compile the Mex funtion to get the rainflow.dll. So for everyone that may have the same problem please read the help carefully.

I made some checks with my working current signals and works fine. It helps a lot to my work thank you very much for sharing it.

Best regards

I got it working.

The idea lies in renaming the rainflow.m to rainflow_1.m or any other name. The demo script rfdemo1 then executes the rainflow.mex which is what is intended.


Dear Adam

I have the same issue of Shashank (23Feb2011). And seems that rfdemo1 calls to rainflow.m that is the description.

Furthermore folloing the instructions I cannot check a simple input like b in the example below. I cannot run the rainflow. I'm not skilled yet on matlab maybe I miss something. Please could orientate us a little bit? thanks
>> rfdemo1
??? Attempt to execute SCRIPT rainflow as a function.

Error in ==> rfdemo1 at 35

>> b

b =

-2 1 -3 5 -1 3 -4 4 -2

>> rf=rainflow(b)
??? Attempt to execute SCRIPT rainflow as a function.


I'm using matlab V7.0.1.24704 R14


First of all, thanks for sharing this awesome tool!

I have a similar problem on my linux pc running Matlab R201b:
??? Attempt to execute SCRIPT rainflow as a function:

Any help on that? :)


Dear Adam

I am getting the problem as some have previously posted.

?? Attempt to execute SCRIPT rainflow as a function.

Error in ==> rfdemo1 at 35

Can you suggest how should I overcome this.




I downloaded the files and tried to run some numbers.
My input was [4 12 7 14 -5 4 -9 7 -1 16].
According to the rainflow method I am familiar with, I expected to get somthing similar to
[4 14 7 12 -5 4 -7 16 -1 7].
Instead, I got the matrix rf with Mean, Amp. , Half/full cycle, begining time and cycle period.

My question is, is it possible to get the result I expected,
i.e. [4 14 7 12 -5 4 -7 16 -1 7].

Thanks in advance,

Dilip Rao

Thank you Adam.I did add the rainflow matrices from every axis separately.

Dilip Rao

HI Adam,
The problem is the matrices are of different sizes and are really huge.Like I have 5 test cycles and x axis data from each cycle of different durations.I cannot add all the cycles as it is huge amount of data,so now can you suggest me how do I take a rainflow of all the cycles combined in one result?

Adam Nieslony

Hi Dilip Rao,
You can add the matrices without problems if they have the same size: m=m1+m2+m3. I don't know what you need exactly to do, but be careful while adding matrices from different sensors - maybe you have multiaxial fatigue problem? I this case use some theoretical criteria for obtaining equivalent uniaxial fatigue loading/matrix.

Dilip Rao

I would like to know if I have a lot of rainflow matrices,how do I add them.
ex. I have data from 3 axes of a sensor and from 3 sensors and I just need one rainflow matrix for all this data.The data for each axis and each sensor is I would like to know how do I get just one rainflow matrix for all the data?

Dilip Rao

Chris Mc

I am quite new to matlab but can anyone tell me if this algorithm can give an output of number of cycles to failure? I am interested to know when a component (modelled in FEA) is going to fail.


Thanks Adam,
I didn't phrase my question correctly, I understand the RFHIST counts cycle amplitudes and not stress ranges now, but what I am trying to figure out is if my rainflow function outputs - rf(3,:) Number of cycles (0.5 or 1.0) and my RFHIST syntax is [no,xo]=rfhist(rf,30) how does the program determine the bin locations or is rf evenly distributed over 30 bins or are the bin locations associated with the number of extracted cycles? Can you please elaborate on this.


Adam Nieslony

Hi Andrew Greaser,
The RFHIST counts cycle amplitudes and not ranges. You can also make an histogram for cycles mean, frequency and period. See help lines included in RFHIST function.

Hello, My question is, how is it determined in the rainflow algorithm what stress ranges and cycle counts are put into each bin to create a rainflow histogram?

Might someone have a data set, with a known answer, to be able to run and understand clearly what the concerns cited above are. Or at least to help understand the nature of what has some concerned about. I want to be sure to not misunderstand something and I don't have data that can help me get to that point. Thanks very much in advance.

Thank you very much Mr. Nieslony.

Adam Nieslony

According message from Scott Richardson, 09 Oct 2010.

There are more than one equation for stress-life characteristics. Probably you are working with the Basquin model:


where b is understood as the curve slope. In my example the Wohler model is used. It is possible, with some restriction, compute the 'm' slope on the basis of Basquin model:


But remember that the first step is clarifying which kind of curve you are using. The Miner rule n/N=1 is used anyway.

Best regards, Adam Niesłony

Hello, my question is regarding the example provided. It's an example, I realize, but I need to know if we're talking about the same thing because it's SO different from what I am used to seeing.

Namely, the slope used is 'm=8', and I am used to seeing slopes for steel of like -0.07. so that makes no sense.

Can someone please provide some clarification of what is meant there.

Thank you.

upna fruit

Hi everyone,
First of all, thanks for your quick response in the previous comment I made. I'va keep on working on fatigue testing and I've found another problem.
I am analysing some test data with this algorithm but another research center is analysing the same data and they are reaching diferent results. They are using the algorithm of Downing and Socie "Simplified Rainflow Counting method".
Is it normal that we obtain different results because of that?

Thanks in advance

upna fruit

Hi everone,
I'm working on fatigue testing and I'm using the rainflow algorithm with long and quite complex signals.
reading thought rfdemo2 I've noticed that the function
sig2ext is called twice. Is that necesary?
I will be gratefull of any help


how to import data in rfdemo2?
Lesson 2 from the html guide works, but what is the syntaz for
Great work

Ahmed Farag

Ahmed Farag

Thanks Adam for your effort and you response to my enquiry, i really appreciate such an awesome routine

Ahmed Farag

I have a problem running the rfdemo1 file , i got this error message
?? Attempt to execute SCRIPT rainflow as a function.

Error in ==> rfdemo1 at 35

Any solution for that

It is very good work

First of all, let me compliment for this excellent piece of software!!

The ASTM standard E 1049 -85 (2005) defines two distinct rainflow algorithms:
A) 5.4.4 "Rainflow counting" (that produces half-cycles)
B) 5.4.5 "Simplified rainflow counting for repeating histories" (that never produces half-cycles)

this is probably the answer to questions like the one of Ray Beale. Now I am interested in the "B" method, and I am asking the author: which algorithm is implemented here? my guess is the "A" method, with half cycles.
Second question: is there some hope to extend this function to be able to compute, optionalyy, also the B way?
If necessary I would be glad to provide more info (namely the text of the ASTM standard).
Best regards and thaks a lot for sharing!

Ray Beale

Sampathkumar- Amplitude is always half the range, by definition.

I am finding many half-cycles in my rfc output of a long time history. Another method I've used produces full cycles. When comparing the two methods for the same time history, the histograms have the exact same shape but your method is shifted to the right due to the unpaired half cycles. Both claim to be ASTM standard. Any idea why?

Jinsuk Lee

I have temperature data over time and derive a fatigue model. Using this rainflow counting, I want to get data with three parameters, which are Max_termperature, each cycle time, amplitude (max-min). Is anyone knowing if this package can provide this kind of data? I appreciate.

On Elena Menéndez's question above, is there an answer. I am finding that amplitude is half the range as well in this method.? Anyone knows why?

"I have noticed one important difference in the rainflow when compared with the rutine used by the software Bladed. The latter always assigns one full cycle to the range (max-min) of the timeseries. However, your rutine assigns 0.5 cycles to this range. Which one is more accurate? "


I found out that my first error came from a conflict caused by a similar filename and function name (Rainflow.m/rainflow) But now my error is:
??? Undefined function or method 'rainflow' for input arguments of type

Error in ==> testinterpolasjon at 19
rf = rainflow(ext,exttime);

I'm running Matlab release 2009a


I can't get this working. I try the rfdemo1 using the syntax found in the rfdemo1.m, f.ex.
rfdemo1([2 3 2 4 2 5 1 6])

My error output is
>> rfdemo1([2 3 2 4 2 5 1 6])
??? Attempt to execute SCRIPT rainflow as a function:
C:\Users\Andreas\Documents\MATLAB\Rainflow cycle counting\rainflow.m

Error in ==> rfdemo1 at 35


Anyone know why?

ap1le q

very good


I have noticed one important difference in the rainflow when compared with the rutine used by the software Bladed. The latter always assigns one full cycle to the range (max-min) of the timeseries. However, your rutine assigns 0.5 cycles to this range. Which one is more accurate?
Thank you

Filip R

Does anyone know how to get output data from rfdemo1? Because i noticed that rainflow.m is not accurate with larger amount of data. Thank you

santosh a

Craig Chang

great tool. Detail doc, easy to use. Excelent.

Félix DORE


syna gupt

I used this toolbox but the result seems not correct....

aid Abdelkrim

Philips Adewuyi

I have been looking for materials that treat the subject of rainflow counting methods for fatigue analysis of structures.

nasri mohamed

methode de rainflow par matlab

Jenyi Liao

David Outcalt

Do you have a commented version of the C code? I find it difficult to follow.

Achalesh Pandey

arif fahruddin

I'm master student, my thesis about fatigue in variable amplitude, random loaing. Have you a solution. Thank You

Carmem Miranda

I am taking Master course in Brazil. My research is on fatigue. I have difficulties to understand the input data for your program “Rainflow Couting Method”. I need a tutorial to the program and/or an input file example. Can you help me?
Thanks for attention

Kerim Genc

Excellent code, very useful. I validated and understood it through trials with small data sets before moving onto huge force-time curves. Make sure that you understand that amplitude is in terms of a sinusoid, therefore the magnitude of the peaks are actually twice the amplitude indicated. Also, Half cycles can be a bit confusing at first, since this is not a "closed loop" rainflow counting method, you just have to combine the half cycles.

rafiq zulkiffli

i have 1 nonlinear equation with 2 unknowns, can u give the example solution using matlab??..this is my equation is

Muhd rafiq

thanks for the advice..but im still got problem coding in Matlab, because i cannot get the peak and valley reversal data length is 32000 and sampling frequency is 200...can u give me some idea...

muhd rafiq zulkiffli

show the code for rain flow cycle counting

Adam Nieslony

Hi Rafiq Zulkiffli,

Some years ago I wrote the rainflow function in MATLAB Script (m-file). Unfortunately the function worked very, very slow, because many iterations in the rainflow algorithm appears. So, I decide to create mex function where the time consuming iterations realized faster. Be sure, with ?the soft code? you cant count the cycles in sensible time. Look on the ?rainflow.c? file and try to understand the C code lines.

Best regards, Adam Nieslony

rafiq zulkiffli

need to show the soft code

Matthew Hoehler

A very useful tool! It is fast, robust and did just what I needed; no more, no less.

gov raj

good approach

Andy Stevenson

This is an excellent tool. I made a couple of short example problems to understand the output and once I did that I'm using the program at work. The rfdemo2 code is especially cool for showing others how rainflow counting works.

Vikas Gupta

This is very best in lot of applications.

Sarah Hughes

Functionally this program is excellent, and produces results that are consistent with the ASTM standard. As with other users, it took me a while to realise that amplitude means amplitude and not range, but that's my fault for not reading it properly. I would appreciate some more explanation of the meaning of the half-cycles which I haven't encountered in other software, as I'm not sure how best to process these.

Joe Quinn

Dr. Nieslony has developed a Rainflow counting application which we used to validate our impemtation of the ASME standard.
Once you know that his cycle size is peak and not peak to peak you can adjust (X2) and then it worked 100%.
Bins boundaries are based on the midpoint between succesive bin midpoints. This caused some juggling to match our method which specifies bin edge directly.
Otherwise, it was accuarate and easy to modify for graphing and printouts.

I am certain that had I been able to read it the Polish comments would have further added to my understanding of the code.

matt matt

Once the entry vector is too large, it doesn't work. Who can help me?

hh hh

BB shine

This program is perfect to me... thanks..

Tomasz Bednarek

aid abdelkrim

- the version matlab does not go
- I need the module mex.h

Ole Dossing

This is a very fine application, not to mention the latest additions. We have used the the rainflow in a stay bridge for fatigue monitoring on critical structures.

muh alat

Steve Grobler

Found teh demo quite informative. Would be helpful if the rainflow results could be arranged in a matrix of cycle counts, with the rows representing the mean, and the columns representing the ranges. Also be helpful if the "leftover" 1/2 cycles could be combined into full cycles and included in the matrix.

abdelkader miloudi

reshu shukla

i want to know that the information about the counting method

Jim Kay

Program works well; does not produce histograms, you need to extract these yourself (watch out for half-cylcles).
Checked against "Simple rainflow counting algorithms" (1 pass methdo), Downing and Socie; got the same results.

Zbo Amigo

Lang naar gezocht, maar nu heb ik het dankzij ZBO!

marc zbo

helemaal top. Mijn dag is gelijk goed

Yu Sang Hui

This is the program that I want to find


Added support for Win64.

Revised for use with latest version of MATLAB.

I add new functions: rfhist and rfmatrix.

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Quick Fatigue Tool