1

I am a new MATLAB user with little programming experience (I have a mechanical engineering background) so I apologise in advance if this is a simple question!

I am trying to import a large point cloud file (.pts file extension) into MATLAB for processing. I'm lead to believe that the file contains a text header and 3 columns of integer data (x, y and z coordinates) - I managed to open the first part of the file as a text file and this is the case.

I cannot import the file directly into MATLAB as it is too large (875 million points) and can only import it 9000000 rows at a time, therefore I have written the script below to import the file (and consequently save) as 9000000x3 blocks, saved as MATLAB files (or another appropriate format).

Script:

filename='pointcloud.pts';
fid = fopen(filename,'r');
frewind(fid);
header=fread(fid,8,'*char');
points=fread(fid,1,'*int32');
pointsinpass=9000000;
numofpasses=(points/pointsinpass)
counter = 1;

while counter <= numofpasses;

   clear block;

   block=zeros(pointsinpass,3);


    for p=1:pointsinpass;
      block(p,[1:3])=fread(fid, 1,'float');
    end;

    indx=counter;
    filename=sprintf('block%d',indx);
    save (filename), block;


    disp('Iteration')
    disp(counter)
    disp('complete')
    counter=counter+1;


end;
fclose(fid);

The script runs fine and cycles through 5 iterations, importing 5 blocks of the data. Then, as it attempts to import the 6th chunk I get the following error:

Subscripted assignment dimension mismatch.

Error in LiDARread_attempt5 (line 22)
          block(p,[1:3])=fread(fid, 1,'float');

I am unsure about what is causing the error, I believe it is relating to fread command size, as I have experimented with various values such as 3, which enables just one block to be imported before the dimension mismatch error occurs.

Once more I apologise if I am missing something very basic, my understanding of programming techniques is very limited only having been introduced to it a couple of months ago.

4

2 に答える 2

0

ある時点で空をfread()返します。[]

エラーを再現する方法を示すことができます:

a = zeros(2,2)
a =
     0     0
     0     0
a(2,1:2) = []

Subscripted assignment dimension mismatch. 

textscan()の代わりに使用することをお勧めしますfread()

于 2013-12-30T21:44:31.240 に答える
0

Matlab は優れたツールですが、大きなデータの問題では苦労します。それは学習曲線を表していますが、Python を調べることをお勧めしますか? 私は何年も前に matlab から python に切り替えましたが、その過程をあまり振り返っていません。

Spyder は強力な IDE http://code.google.com/p/spyderlib/であり、matlab ユーザーに適切な橋渡しを提供します。Windows 用のPythonxy http://code.google.com/p/pythonxy/は、そのプラットフォームで生産性を高めるために必要なすべてのツールを提供しますが、最後に 32 ビット アドレス空間しかサポートしていないことを確認しました。Windows で 64 ビットのサポートが必要な場合は、http: //www.lfd.uci.edu/~gohlke/pythonlibs/でhttps://stackoverflow.com/users/453463/cgohlkeが提供する素晴らしいパッケージがあります。 Linux では、必要なすべてのパッケージを非常に簡単にインストールできます。必要なパッケージとの完全な互換性のために、すべての場合で python2.7 を使用する必要があります

私はあなたの問題の詳細をすべて知っているわけではありませんが、numpy memmap データ構造を使用するとおそらく役立つでしょう。これにより、アレイ全体をメイン メモリにロードすることなく、巨大なアレイをディスクから操作できます。それはあなたのために内部を処理します。

基本的に行うことは次のとおりです。

##memmap example
#notice we first use the mdoe w+ to create.  Subsequent reads 
#(and modifications can use r+)
fpr = np.memmap('MemmapOutput', dtype='float32', mode='w+', shape=(3000000,4))
fpr = numpy.random.rand(3000000,4)
del fpr #this frees the array and flushes to disk
fpr = np.memmap('MemmapOutput', dtype='float32', mode='r+', shape=(3000000,4))
fpr = numpy.random.rand(3000000,4)#reassign the values - in general you might not need to modify the array. but it can be done
columnSums = fpr.sum(axis=1) #notice you can use all the numpy functions seamlessly
del fpr #best to close the array again when done proces

これを間違った方法で受け取らないでください。私はあなたに matlab を放棄するよう説得しようとしているわけではありませんが、ツールセットに別のツールを追加することを検討してください。

于 2013-12-31T13:12:40.700 に答える