使用polyarea计算子循环的面积

时间:2017-06-26 18:32:49

标签: matlab area cyclic

我想知道如何在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

1 个答案:

答案 0 :(得分:0)

假设每个周期具有相同的已知持续时间(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教程可能会有用。