美文网首页
2019-10-08

2019-10-08

作者: hao_c130 | 来源:发表于2019-10-08 14:01 被阅读0次

    '''

    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;

    '''

    相关文章

      网友评论

          本文标题:2019-10-08

          本文链接:https://www.haomeiwen.com/subject/pgsbpctx.html