Separate large array into equal sizes

Hi guys, first time posting.
I'm trying to separate a large array (351030x2) into arrays all of size 1500x2
I'm thinking mat2cell would be the best way to go about it but I do not want to have to type out all of the multiples of 1500 to 351030.
Any help appreciated! shan.

1 个评论

351030 is not divisible by 1500 exactly, what do you do with the last 30?
I would not recommend creating 234 variables out of one. You should be able to do whatever processing you want on that one array.
A cell array would certainly be a way to still end up with a single variable containing matrices divided up differently. I never really use mat2cell and got confused when I did, but it has a help page. I think it would also need you to have your data size as an integer multiple of 1500 though to use it as a single instruction.
If your size was precisely divisible by 1500 then I would suggest you should instead just reshape the data to e.g.
1500 * 234 * 2
and use it still as a single data matrix.

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2015-12-14
A question I also have is what are you going to do with the blocks once they've been separated out. That may have some bearing in how you divide this into blocks. For example, there are a couple of ways detailed in the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
See if this does what you want:
M = randi(99, 351030, 2); % Create Data Matrix
RowDes = 1500; % Desired Cell Row Length
Row15 = fix(size(M,1)/RowDes); % Number Of Desired Length Cells In Output
LeftOver = rem(size(M,1),RowDes); % Cell Of Remaining Rows
MC = mat2cell(M, [ones(1,Row15)*RowDes, LeftOver], 2); % Desired Result (?)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

提问:

dip
2015-12-14

回答:

2015-12-14

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by