Search code examples
matlabareacyclic

Using polyarea to calculate the area of a subcycle


I was wondering how to use polyarea in MATLAB at different intervals. For example, I have disp=[1,2,3,4,5.....] and load = [3,4,5,6,7,8....]. I would like to calculate polyarea(disp,load) at every 40 rows (or intervals). disp and load are cyclic loading and displacement data, containing 1000+ rows like this. Any help is much appreciated!

EDIT 1: (based on m7913d's answer) It seems the code is somewhat not giving the answers appropriately. Is anything wrong with the code?

data=xlsread('RE.xlsx');
time=data(:,1);
load=data(:,2);
disp=data(:,3);
duration = 40;
n = length(disp); % number of captured samples
nCycles = floor(n/duration); % number of completed cycles
areas = zeros(nCycles, 1); % initialise output (area of each cycle)
for i=1:nCycles % loop over the cycles
    range = (i-1)*duration + (1:duration); % calculate the indexes corresponding with the ith cycle
    areas(i) = polyarea(disp(range), load(range)); % calculate the area of the ith cycle
end

Solution

  • Assuming each cycle has the same known duration (duration = 40), you can calculate the area of each cycle as follows:

    duration = 40;
    n = length(A); % number of captured samples
    nCycles = floor(n/duration); % number of completed cycles
    areas = zeros(nCycles, 1); % initialise output (area of each cycle)
    for i=1:nCycles % loop over the cycles
        range = (i-1)*duration + (1:duration); % calculate the indexes corresponding with the ith cycle
        areas(i) = polyarea(A(range), B(range)); % calculate the area of the ith cycle
    end
    

    Further Reading

    As this seems a basic question to me, it may be useful to have a look at the Getting Started tutorial of MATLAB.