Hi,
I have a cell matrix of 300,000 x 100 format. By using for loops, I want to make a new matrix every 10,000 rows while naming each different matrix automatically. For instance, a matrix that contains 1:10,000 from the original huge matrix will have something like matrix_1 as follows:
matrix_1 = [1:10,000,:];
matrix_2 = [10,001:20,000,:];
.
.
.
.
matrix_20 = [190,001:200,000,:];
Would you mind sharing your thoughts on this?
Thanks for your help in advance!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 2일
편집: Azzi Abdelmalek 2016년 5월 2일

0 개 추천

This is not good, Use instead a cell array
matrix{1} = [1:10];
matrix{2} = [1:20]

댓글 수: 3

blocksize = 10000;
numrow = size(YourMatrix,1);
num_blocks = floor(numrow/blocksize);
blocks = blocksize * ones(1, num_blocks));
rowsused = num_blocks * blocksize;
if rowsused ~= numrow
blocks(end+1) = numrow - rowused;
end
matrix = mat2cell(YourMatrix, blocks, size(YourMatrix,2));
Now matrix{1} will be the first 10000, matrix{2} will be the second, and so on, and the last entry will have fewer than 10000 if YourMatrix is not an even multiple of 10000 rows.
Thanks Walter! This helps. However, I forgot to mention earlier that the original matrix that I have is based on text.file. So, after running script as you can see below, I have tmp = {284781x1 cell}, which is actually 53 columns (i.e. variables) existing within this cell structure format for each row.
fid = fopen(filename,'r');
tmp = textscan(fid,'%s','Delimiter','\n');
Given a suggested solution you mentioned above, I have 100,000 rows (1X411 char) in each matrix which is remaining a char format.
How can I break each row of char format and convert into cell matrix as a result?? Thus, I want to have a cell matrix of [100,000 x 53] instead of a char matrix of [100,000 x 1]...
Please share your thoughts. Thanks for your help again!!!
YourMatrix = char(tmp);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2016년 5월 2일

댓글:

2016년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by