Split a matrix according to sizes of cell arrays and store the result in cells/table
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/594970/image.png)
0 commentaires
Réponses (1)
Tarunbir Gambhir
le 26 Avr 2021
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
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!