在MATLAB矩阵阵列 [英] Array of Matrices in MATLAB

查看:338
本文介绍了在MATLAB矩阵阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方法来存储在MATLAB数组大量可变数量矩阵。

是否有实现这一目标的任何方式?

例如:

 对于i:1:未知
  myArray的(ⅰ)=零(500,800);
结束

在哪里未知数是数组的长度不同的,我可以,如果需要额外的信息修改。

更新:
性能我试图做到这一点的主要原因。我哪里会抓取数据作为一个矩阵,显示它在实时,然后继续处理下一组数据之前,有它。

我试图用它多维数组由罗科以下建议,但是我的数据是如此之大,我跑出记忆,我可能不得不考虑另一种选择我的情况。将更新,我尝试其他建议。

更新2:
谢谢大家的建议,但我应该有事先指定,precision和速度都在这里不可或缺的因素,我可能会考虑回去我原来的方法尝试3维数组前,重新评估方法导入的数据。


解决方案

如果所有的矩阵将是相同的大小(即500x800),那么你可以做一个三维数组:

  n未知; %未知阵列的数
myArray的=零(500,800,n未知);

要访问一个数组,可以使用下面的语法:

 子矩阵= myArray的(:,:,3); %获取第三矩阵

您可以在几个方面增加更多的矩阵来myArray的

  myArray的=猫(3 myArray的,零(500,800));
% 要么
myArray的(:,:,n未知+ 1)=零(500,800);

如果每个矩阵不会是相同的大小,你需要使用电池阵列像胡沙姆建议。

编辑:我错过了大约运行内存的一部分。我猜你的n未知是相当大的。您可能需要(如果你使用的是单一的整数甚至uintXX型)切换矩阵的数据类型。您可以在调用零做到这一点:

  myArray的=零(500,800,n未知,'单');

I am looking for a way to store a large variable number of matrixes in an array in MATLAB.

Are there any ways to achieve this?

Example:

for i: 1:unknown
  myArray(i) = zeros(500,800);
end

Where unknown is the varied length of the array, I can revise with additional info if needed.

Update: Performance is the main reason I am trying to accomplish this. I had it before where it would grab the data as a single matrix, show it in real time and then proceed to process the next set of data.

I attempted it using multidimensional arrays as suggested below by Rocco, however my data is so large that I ran out of Memory, I might have to look into another alternative for my case. Will update as I attempt other suggestions.

Update 2: Thank you all for suggestions, however I should have specified beforehand, precision AND speed are both an integral factor here, I may have to look into going back to my original method before trying 3-d arrays and re-evaluate the method for importing the data.

解决方案

If all of the matrices are going to be the same size (i.e. 500x800), then you can just make a 3D array:

nUnknown;  % The number of unknown arrays
myArray = zeros(500,800,nUnknown);

To access one array, you would use the following syntax:

subMatrix = myArray(:,:,3);  % Gets the third matrix

You can add more matrices to myArray in a couple of ways:

myArray = cat(3,myArray,zeros(500,800));
% OR
myArray(:,:,nUnknown+1) = zeros(500,800);

If each matrix is not going to be the same size, you would need to use cell arrays like Hosam suggested.

EDIT: I missed the part about running out of memory. I'm guessing your nUnknown is fairly large. You may have to switch the data type of the matrices (single or even a uintXX type if you are using integers). You can do this in the call to zeros:

myArray = zeros(500,800,nUnknown,'single');

这篇关于在MATLAB矩阵阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆