全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2486
推到 Plurk!
推到 Facebook!

如何從txt檔中將其值存成矩陣??

答題得分者是:BON362
parano
一般會員


發表:14
回覆:6
積分:4
註冊:2007-02-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-06-08 18:36:23 IP:140.114.xxx.xxx 訂閱
<textarea class="cpp" rows="10" cols="60" name="code"> void __fastcall TForm1::Button8Click(TObject *Sender) { Graphics::TBitmap *TheBitmap, *TempBitmap; unsigned short Width=0, Height=0; unsigned short clRGB=0,c2RGB; unsigned short ***pix,***pix1; float ***Intp; float ***ML; float ***F; float ***Gou; unsigned short T=0; unsigned short i=0; unsigned short nn=0; unsigned short max=0; unsigned short ifx=0,ify=0,idx=0,idy=0; float Por=0; unsigned short T_sml=0; unsigned short Depth_mag=0; float maxvalue=0; float dx=0,dy=0,fx=0,fy=0,nfx=0,nfy=0; unsigned short N=0; float Xw=0,Yw=0,Zw=0; double start,end,tot_time; AnsiString Dir; T=StrToInt(Edit4->Text); //欲處理之影像張數 T_sml=StrToInt(Edit2->Text); //低於閥值,視為背景 Depth_mag=StrToInt(Edit3->Text); //深度倍率 N=StrToInt(Edit5->Text); //聚焦度量測視窗尺寸N*N Por=StrToFloat(Edit7->Text); //換算比例 dx=StrToFloat(Edit8->Text); //第一張圖跟最後一張圖的x偏移量 dy=StrToFloat(Edit9->Text); //第一張圖跟最後一張圖的y偏移量 if (OpenDialog1->Execute()) Dir=ExtractFileDir(OpenDialog1->FileName); AnsiString Txtname; if(OpenDialog2->Execute()) { Txtname=OpenDialog2->FileName ".txt"; } FILE *fp,*fp1; fp=fopen(Txtname.c_str(),"w"); //fp1=fopen("constract.txt","w"); pix=new unsigned short**[T]; start=clock(); for (unsigned short i=0;iProcessMessages(); //Sleep(200); AnsiString FileName=Dir "\\" IntToStr(i) ".bmp"; Image1->Picture->LoadFromFile(FileName.c_str()); Form1->Caption=FileName; TempBitmap= new Graphics::TBitmap(); TheBitmap=Image1->Picture->Bitmap; TempBitmap->Assign(TheBitmap); Width= TheBitmap->Width; Height= TheBitmap->Height; pix[i]=new unsigned short*[Height]; for(unsigned short y=0;yCanvas->Handle,x,y); c2RGB=(GetRValue(clRGB)*77 GetGValue(clRGB)*151 GetBValue(clRGB)*28)/256; pix[i][y][x]=c2RGB; } } //影像灰階值讀取結束 } //I迴圈結束!! pix1=new unsigned short**[T]; for (unsigned short i=0;i 想請問各位大大,如何將txt檔的第一行和第二行存成矩陣[i]和[j],以便之後利用??
編輯記錄
parano 重新編輯於 2007-06-08 18:49:08, 註解 無‧
parano
一般會員


發表:14
回覆:6
積分:4
註冊:2007-02-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-06-08 18:38:18 IP:140.114.xxx.xxx 訂閱
我的txt檔格式如下所示:
0 0
0.2 0.3
0.5 0.6
0.25 0.347
0.23 0.6
0.25 0.36
. .
. .
. .
編輯記錄
parano 重新編輯於 2007-06-08 18:39:52, 註解 無‧
parano 重新編輯於 2007-06-08 18:43:38, 註解 無‧
BON362
一般會員


發表:3
回覆:16
積分:13
註冊:2007-05-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-07-12 17:23:00 IP:211.20.xxx.xxx 訂閱
我是用c++寫的,讀的檔案是"123.txt"你把他轉放到bcb是可以用的,不知道這是你要個東西嗎??

<textarea cols="60" rows="10" class="cpp" name="code"> #include #include #include int main() { char filename[20]="123.TXT"; float a[50],b[50],bin=12.554; FILE *ifp; if((ifp= fopen(filename,"r")) == NULL){ printf("file not open or find"); getchar(); exit(1); } int i=0,j=0; while(fscanf(ifp,"%f",&bin)!=EOF){ a[i]=bin; i ; b[j]=bin; j ; } for(int k=0;k
===================引 用 parano 文 章===================
我的txt檔格式如下所示:
0 0
0.2 0.3
0.5 0.6
0.25 0.347
0.23 0.6
0.25 0.36
. .
. .
. .
------
加油吧 C
系統時間:2024-05-02 12:58:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!