2019-10-08

2019-10-08  本文已影响0人  hao_c130

'''

function gets(filename)

global x;

global y;

%global len;

[~,~, raw] = xlsread(filename);

len = length(raw);

x = cell2mat(raw(2:len,1));%第一列数据

y = cell2mat(raw(2:len,2));%第二列数据

len = len-1;

lengt  = len;  %从读取数据来的数据数目

clear p;

p.x = zeros(lengt,1);  % 初始化结构体等

p.y = zeros(lengt,1);

s = 0;

for count =1:lengt        %将数据赋值到P点

    p(count).x = x(count);

    p(count).y = y(count); 

end

for count2 = 1 :lengt-1

s = s +getcha(p(count2),p(count2+1));

end

s =s + getcha(p(lengt),p(1));

s = 0.5 * abs(s)

function cha = getcha(p1,p2)

cha =p1.x * p2.y - p2.x * p1.y;

'''

上一篇下一篇

猜你喜欢

热点阅读