使用 polyarea 计算子循环的面积

Using polyarea to calculate the area of a subcycle

我想知道如何在 MATLAB 中以不同的时间间隔使用 polyarea。例如,我有 disp=[1,2,3,4,5.....]load = [3,4,5,6,7,8....]。我想每 40 行(或间隔)计算 polyarea(disp,load)。 disp 和 load 是循环加载和位移数据,包含 1000+ 行这样的。任何帮助深表感谢!

编辑 1: (基于 m7913d 的回答) 代码似乎没有给出适当的答案。代码有问题吗?

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

假设每个周期具有相同的已知持续时间(duration = 40),您可以计算每个周期的面积如下:

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

进一步阅读

因为这对我来说似乎是一个基本问题,所以看一下 MATLAB 的 Getting Started 教程可能会有用。