Too many input arguments error when cell2mat and mean functions are used
Mostra commenti meno recenti
I have five cluster data saved in my cell array iniclu. Each row of cell array contains varying number of columns such as 23 27 26 17 7 so that the shortage of columns are marked as [] to the max of 27. Now i want to process cell array row one by one to find mean or centroid of each cluster. My usage is shown in code, but it throws error.
count = [23 27 26 17 7]
iniclu = cell(1,1); %later i built the cluster data as shown in fig
for i = 1:5
bb = [];
bb = cell2mat(iniclu{i,1:count(i)});
centroids(i,:) = mean(bb,1);
end
But it throws too many input arguments error, hence i could not get expected op as centroids having 5x2 means data. I have attached content of iniclu data.
Pls clarify!
Pls clarify!3 Commenti
Chuguang Pan
il 13 Mar 2024
bb=cell2mat(iniclu(i,:));
NALLARASU KRISH
il 13 Mar 2024
Walter Roberson
il 13 Mar 2024
no, you have different sizes of cells; you can only put them together as a vector (unless you are willing to pad the entries)
Risposta accettata
Più risposte (1)
VBBV
il 13 Mar 2024
1 voto
bb = cell2mat(iniclu(i,1:count(i)));
Use a ( ) in place of { }
9 Commenti
VBBV
il 13 Mar 2024
If you use { } the result is not a cell, so you don't need cell2mat function to convert
NALLARASU KRISH
il 13 Mar 2024
@NALLARASU KRISH, you can get the cell2mat output as 23 x 2 if you reshape
bb = cell2mat(iniclu(i,1:count(i)));
bb = reshape(bb,[],2);
centroids{i} = mean(bb,1); % The 5th row unequal data size compared to remaining rows
NALLARASU KRISH
il 13 Mar 2024
@NALLARASU KRISH, ok, try the below
bb = cell2mat(iniclu(i,1:count(i)));
bb = reshape(bb,2,[]).';
centroids{i} = mean(bb,1); % The 5th row unequal data size compared to remaining rows
NALLARASU KRISH
il 13 Mar 2024
@NALLARASU KRISH you have used the below line incorrectly, it should be as shown below
bb = reshape(bb,2,[]).';
NALLARASU KRISH
il 13 Mar 2024
Look at the sizes of the outputs and the arrangement of data in those outputs.
bb = 1:10
bb1 = reshape(bb, 2, []).'
bb2 = reshape(bb, [], 2).'
Categorie
Scopri di più su Cell Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!