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
2015년 12월 14일
0 개 추천
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
Star Strider
2015년 12월 14일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!