[運算]將txt讀成矩陣, 遇到out of memory的問題

看板MATLAB作者 (嗶Be)時間9年前 (2014/11/26 15:07), 編輯推噓2(202)
留言4則, 4人參與, 最新討論串1/1
我有一個大小為34.8G的txt檔, 裡面都是0.XXXXXX 的六位小數點數值, 當初在寫這份檔 案的時候, 是在matlab下使用dlmwrite('data.txt', A, '-append' ), 慢慢將每一條向 量A寫入的。 但我利用dlmread('data.txt')來讀入矩陣時, 約莫讀了一個小時半後, 出現了錯誤訊息: Error using dlmread (line 139) Out of memory. Type HELP MEMORY for your options. 本想打入指令memory來看看記憶體狀況, 卻出現 Error using memory Function MEMORY is not available on this platform. 可能因為我的作業系統是Ubuntu吧! 然後load('data.txt')則是出現: Error using load Number of columns on line 97 of ASCII file /media/Action/data.txt must be the same as previous lines. 我也使用過importdata('data.txt'), 可是跑了一陣子後, 整個matlab就被killed, 感覺 是超出可使用的memory, 被OS殺掉。 後來想一想, 我的memory有32G, 而檔案卻有34.8G, 要把這麼大一個矩陣讀入是否根本不 可行? 若可行的話, 有甚麼做法呢? (補充一下,此矩陣接下來需要拿來做k-means) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.123.102.130 ※ 文章網址: http://www.ptt.cc/bbs/MATLAB/M.1416985628.A.022.html

11/26 15:59, , 1F
先切檔再讀?
11/26 15:59, 1F

11/26 16:25, , 2F
推樓上,你的檔案是ASCII格式,讀進來後會小很多。
11/26 16:25, 2F

11/26 16:40, , 3F
.... 一次讀 34G 的檔案 !!!
11/26 16:40, 3F

11/27 14:11, , 4F
請問切檔再讀是一個個把檔案讀成矩陣,然後再合併矩陣嗎
11/27 14:11, 4F
文章代碼(AID): #1KTNmS0Y (MATLAB)