필터 지우기
필터 지우기

Too many input arguments error when cell2mat and mean functions are used

조회 수: 5 (최근 30일)
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!
  댓글 수: 3
NALLARASU KRISH
NALLARASU KRISH 2024년 3월 13일
Thank you. But your answer partially solves the problem when i try to calculate mean. Can't i get cell2mat output as ,for ex first cell row, 23x2 size instead of 1x46 double?
Walter Roberson
Walter Roberson 2024년 3월 13일
no, you have different sizes of cells; you can only put them together as a vector (unless you are willing to pad the entries)

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

채택된 답변

Stephen23
Stephen23 2024년 3월 13일
편집: Stephen23 2024년 3월 13일
V = [23;27;26;17;7];
N = numel(V);
C = nan(N,2);
for k = 1:N
M = vertcat(iniclu{k,1:V(k)}); % comma-separated list
C(k,:) = mean(M,1);
end

추가 답변 (1개)

VBBV
VBBV 2024년 3월 13일
bb = cell2mat(iniclu(i,1:count(i)));

Use a ( ) in place of { }

  댓글 수: 9
NALLARASU KRISH
NALLARASU KRISH 2024년 3월 13일
OMG! This is working, you are really great. Thank you!! I accept this answer too. Sorry for my carelessness. Could you explain the difference bw bb = reshape(bb,2,[]).'; and bb = reshape(bb,[],2).'; that did the magic, @VBBV ?
Steven Lord
Steven Lord 2024년 3월 13일
Look at the sizes of the outputs and the arrangement of data in those outputs.
bb = 1:10
bb = 1×10
1 2 3 4 5 6 7 8 9 10
bb1 = reshape(bb, 2, []).'
bb1 = 5×2
1 2 3 4 5 6 7 8 9 10
bb2 = reshape(bb, [], 2).'
bb2 = 2×5
1 2 3 4 5 6 7 8 9 10

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by