splitting a cell array and determining its size

Imagine that you have a cell array and you want to determine its size. What command would you use for it? Also how do I split the data of the cell array into half. lets say it has 60 rows and and i want it to be split after 30 rows.
thanks

 채택된 답변

Guillaume
Guillaume 2014년 12월 20일

2 개 추천

Funnily enough. size is the function to get the size of cell arrays and matrices. If you want to split along rows, either use size or end:
c = num2cell(randi(200, 60, 5));
tophalf = c(1: ceil(end / 2), :); %equivalent to c(1 : ceil(size(c, 1) / 2), :)
bottomhalf = c(ceil(end / 2) + 1 : end, :);

댓글 수: 3

AA
AA 2014년 12월 20일
thanks, I mean size as in bytes.
Also your code is easy to understand. If I have 60 rows and I want the tophalf to be 4 rows and the bottomhalf to be 56 rows then how do i implement these changes? thanks
To get the memory footprint of a variable it's whos
c = num2cell(randi(200, 60, 5));
msize = whos('c')
As for splitting:
tophalf = c(1:4, :);
bottomhalf = c(end-56+1:end, :);
That's a funny definition of "half".

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

AA
2014년 12월 20일

댓글:

2014년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by