# Split a matrix according to sizes of cell arrays and store the result in cells/table

조회 수: 1 (최근 30일)
Franz Lehner . 2021년 4월 23일
답변: Tarunbir Gambhir . 2021년 4월 26일
Hey. I have a matrix A of the size 26813x2 which contains data (classifier posterior probabilities for IR spectra) I collected from 104 sample positions.
I have stored the original spectra of this set in cells in tbl.spectra in a table tbl, along with the other information. (see image)
What I need to do now is split this matrix A into submatrices/cells that have exactly the size of the rows in the cells in tbl.spectra, so that I can then add them to another column in the table to clearly identify to which measuring position/patient my data in A belongs.
I am pretty sure mat2cell is the function to use here. Unfortunately, the rowDist is not uniform, otherwise it would be easy. Usually, there are 256 spectra recorded per position, but some had to removed before classification.

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

### 답변 (1개)

Tarunbir Gambhir 2021년 4월 26일
For this scenario, you can probably set a for loop to split the matrix "A" into cells with the same row dimensions as tbl.spectra. You can try out the following approach.
% random data setup
A = rand(256*4,2);
spectra = cell(4,1);
spectra{1} = rand(255,441);
spectra{2} = rand(257,441);
spectra{3} = rand(254,441);
spectra{4} = rand(258,441);
tbl = cell2table(spectra);
% Splitting of A into cells according to content in tbl.spectra
Asplit = cell(4,1);
offstart = 1;
for i =1:length(tbl.spectra)
Asplit{i} = A(offstart:size(tbl.spectra{i},1)+offstart-1,:);
offstart = offstart + size(tbl.spectra{i},1);
end

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

### 카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by