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 位支持,有https://stackoverflow.com/users/453463/cgohlkehttp://www.lfd.uci.edu/~gohlke/pythonlibs/ 上提供的很棒的包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 回答