⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uincwdist.pas

📁 clusterfilesrev 最新的分类聚类代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          FN:=FileName;
          AssignFile(outf,FN);
      end;

    Rewrite(outf);            //  僼傽僀儖傪彂偒弌偟梡偵愝掕

    with StringGrid2 do
      begin
        writeln(outf,RowCount-1);
        for i:=1 to RowCount-1 do writeln(outf,Cells[1,i]);
      end;
    with StringGrid1 do
      begin
        for h:=2 to RowCount-1 do
          begin
            for i:=1 to h-1 do
              writeln(outf, Trim(Cells[i,h])); //  僨乕僞偺彂偒弌偟
          end;
      end;

    CloseFile(outf);
    WardButton.SetFocus;
    CentroidButton.SetFocus;
end;

(*    僼傽僀儖偐傜僌儕僢僪傊僨乕僞傪撉傒崬傓    *)
procedure TFDist.LoadButtonClick(Sender: TObject);
var inf : TextFile;
    v, h, i   : Longint;
    s      : string;
begin
    with OpenDialog1 do           //  僼傽僀儖柤偺愝掕
      begin
          Title:='僼傽僀儖柤';
          FileName:='';
          if not Execute then exit;
          AssignFile(inf,FileName);
      end;

    Reset(inf);                  //   僼傽僀儖傪撉傒弌偟梡偵愝掕

    with StringGrid2 do
      begin
          readln(inf, v);
          RowCount:=v+1;
          for h:=1 to v do
            begin
              Cells[0,h]:=' 懳徾'+IntToStr2(h);
              readln(inf,s);
              Cells[1,h]:=s;
            end;
      end;
    with StringGrid1 do
      begin
        ColCount:=v+1;
        RowCount:=v+1;
        for h:=1 to v do
          for i:=h to v do Cells[i,h]:='*';
        for h:=2 to v do
          for i:=1 to h-1 do
            begin
              readln(inf,s);     //    僨乕僞偺撉傒崬傒
              Cells[i,h]:=s;
            end;

        for h:=1 to v do
          begin
              Cells[0,h]:=' 懳徾'+IntToStr2(h);
              Cells[h,0]:=' 懳徾'+IntToStr2(h);
          end;
      end;

    CloseFile(inf);
    WardButton.SetFocus;
    CentroidButton.SetFocus;
end;

procedure TFDist.PButtonClick(Sender: TObject);
var   pout : TextFile;
      h, i    : Longint;

  function AdjStrL( s : string; L : integer ) : string;
    var w, i : integer;
    begin
        w:=Length(s);
        if w < L then
          for i:=1 to L-w do s:=s+' ';
        AdjStrL:=s;
    end;

begin
      with printer do
        begin
          AssignPrn(pout);
          Rewrite(pout);

          with Canvas.Font do
            begin
                Name:='俵俽 柧挬';
                size:=12;
            end;

          writeln(pout);
          writeln(pout);
          writeln(pout,'Data =');
          writeln(pout);

          with StringGrid2 do
            for h:=0 to RowCount-1 do
              begin
                for i:=0 to ColCount-1 do
                  write(pout,AdjStrL(Cells[i,h],10));
                writeln(pout);
              end;
          writeln(pout);

          with StringGrid1 do
            for h:=0 to RowCount-1 do
              begin
                for i:=0 to ColCount-1 do
                  write(pout,AdjStrL(Cells[i,h],10));
                writeln(pout);
              end;
          CloseFile(pout);
        end;

      WardButton.SetFocus;
      CentroidButton.SetFocus;
end;


procedure TFDist.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
       if ckFSim = 0 then ckFSim:=1;      //   repeat...until暥傪敳偗弌偡
end;

//   Excel屳姺偺偨傔CSV宍幃偱僼傽僀儖弌椡
procedure TFDist.WRCSVButtonClick(Sender: TObject);
var outf : TextFile;
    FN   : string;
    h, i : Longint;

  function CheckCSV( s : string ) : string;
    begin
        if Length(s) < 5 then s:=s+'.csv'
        else if  (Copy(s, Length(s)-3,4) <> '.csv')
               and
                 (Copy(s, Length(s)-3,4) <> '.CSV') then s:=s+'.csv';
        CheckCSV:=s;
    end;

begin
    with SaveDialog1 do        //   曐懚梡僼傽僀儖偺柤慜偺愝掕
      begin
          Title:='僼傽僀儖柤';
          Filter:='CSV files (*.csv)|*.CSV';
          FileName:='';
          if not Execute then exit;
          FN:=CheckCSV(FileName);
          AssignFile(outf,FN);
          Filter:='';
      end;

    Rewrite(outf);            //  僼傽僀儖傪彂偒弌偟梡偵愝掕

    with StringGrid2 do
      begin
        for i:=1 to RowCount-1 do write(outf,',', Cells[1,i]);
        writeln(outf);
      end;
    with StringGrid1 do
      begin
        writeln(outf, StringGrid2.Cells[1,1]);
        for h:=2 to RowCount-1 do
          begin
            write(outf, StringGrid2.Cells[1,h]);
            for i:=1 to h-1 do
              write(outf, ',', Trim(Cells[i,h])); //  僨乕僞偺彂偒弌偟
            writeln(outf);
          end;
      end;

    CloseFile(outf);
    WardButton.SetFocus;
    CentroidButton.SetFocus;
end;


//   Excel偵傛傞CSV宍幃弌椡偺僨乕僞僼傽僀儖傪撉傒崬傓
procedure TFDist.RDCSVButtonClick(Sender: TObject);
var inf : TextFile;
    s   : string;
    i, j, n : Longint;
    SL   : TStringList;
begin
    with OpenDialog1 do        //   曐懚梡僼傽僀儖偺柤慜偺愝掕
      begin
          Title:='僼傽僀儖柤';
          Filter:='CSV files (*.csv)|*.CSV';
          FileName:='';
          if not Execute then exit;
          AssignFile(inf,FileName);
          Filter:='';
      end;

    Reset(inf);            //  僼傽僀儖傪彂偒弌偟梡偵愝掕
    SL:=TStringList.Create;
    readln(inf, s);
    SL.CommaText:=s;
    n:=SL.Count-1;         //  崁栚悢偺愝掕

    with StringGrid2 do
      begin
        RowCount:=n+1;

        for i:=1 to RowCount-1 do
          begin
            Cells[0,i]:=' 懳徾'+IntToStr2(i);
            Cells[1,i]:=SL.Strings[i];
          end;
      end;

    with StringGrid1 do
      begin
        RowCount:=n+1;
        ColCount:=n+1;
        for i:=1 to n do
          begin
            Cells[0,i]:=' 懳徾'+IntToStr2(i);
            Cells[i,0]:=' 懳徾'+IntToStr2(i);
          end;
        readln(inf);
        for i:=2 to n do
          begin
              readln(inf, s);
              SL.CommaText:=s;
              for j:=1 to i-1 do Cells[j,i]:=SL.Strings[j];
          end;
        for i:=1 to n do
          for j:=i to n do Cells[j,i]:='*';
      end;

    SL.Free;
    CloseFile(inf);
    WardButton.SetFocus;
    CentroidButton.SetFocus;
end;

procedure TFDist.CloseButtonClick(Sender: TObject);
begin
       ckFSim:=9;
       Close;
end;

procedure TFDist.CentroidButtonClick(Sender: TObject);
var   i, j  : Longint;
begin
    with StringGrid2 do
      begin
        N:=RowCount-1;   //   懳徾偺愝掕
        for i:=1 to N do
          LObj[i]:=Cells[1,i];
      end;

    with StringGrid1 do
      begin
        try
        for i:=2 to N do
          for j:=1 to i-1 do
            Dist[i,j]:=StrToFloat(Cells[j,i]);

        except                             //   晄惓側僨乕僞
          ShowMessage('Error ===>  Cells['+IntToStr(i)+
                      ','+IntToStr(j)+'] = '+Cells[j,i]);
          Exit;   //   偙偺庤懕偒偺廔椆
        end;
      end;

    DistType:=DCentroid;
    ckFSim:=1;    //   偙偺僼僅乕儉傪惗惉偟偨儐僯僢僩偵偍偗傞
    Close;        //   repeate...until暥傪敳偗弌偡
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -