count number of index in many vector

4 次查看(过去 30 天)
if i have
A{1} = 2
8
1
1
then the solution will be 4
A{2} = 1
3
5
4
5
2
then the solution will be 6
A{3} = 4 5 3 2 5 3 1
then the solution will be 7
i need this solution for A{k}
  1 个评论
Jung Soo Park
Jung Soo Park 2016-4-2
编辑:Walter Roberson 2016-4-2
I hope this is what you want..
I assume k=4 and made A{4} with 14 numbers and expected so expected solution is 14.
k=4;
A=[];
A{1}=[2;8;1;1] ;
A{2}=[1;3;5;4;5;2];
A{3} = [4,5,3,2,5,3,1];
A{4}=[4,5,3,2,5,3,1,4,5,3,2,5,3,1];
S=zeros(1,k);
for i=1:k
s=(size(A{i}));
S(1,i)=max(s);
end
S

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2016-4-2
cellfun( @length, A)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by