Num2cell question

5 views (last 30 days)
Arjun k
Arjun k on 23 Nov 2022
Commented: John D'Errico on 23 Nov 2022
I have a data of size 1440*720*102 double. I want to convert it into a cell structure, I used num2cell but I am hitting bricks !

Answers (2)

Torsten
Torsten on 23 Nov 2022
Most probably too large for your computer:
A = rand(12,3,5)
A =
A(:,:,1) = 0.3275 0.4565 0.9054 0.7983 0.5975 0.2010 0.2198 0.2999 0.8786 0.9899 0.9124 0.3179 0.9665 0.3451 0.1311 0.2861 0.9911 0.9365 0.9874 0.9247 0.4403 0.8435 0.8488 0.3430 0.0910 0.2928 0.0985 0.0995 0.6732 0.3981 0.2617 0.1184 0.3649 0.8339 0.7366 0.2909 A(:,:,2) = 0.0398 0.1426 0.6770 0.9303 0.4939 0.5339 0.0665 0.4595 0.4976 0.0761 0.6740 0.3230 0.3805 0.4837 0.0900 0.8389 0.8596 0.8293 0.9910 0.0807 0.7654 0.4896 0.4105 0.4247 0.6137 0.7339 0.8006 0.4384 0.6656 0.1509 0.2105 0.3942 0.8460 0.5686 0.6290 0.2638 A(:,:,3) = 0.0842 0.9096 0.2395 0.3705 0.6611 0.8899 0.7653 0.4083 0.4778 0.9416 0.9301 0.0006 0.8523 0.7219 0.8770 0.5199 0.7490 0.7645 0.8845 0.4652 0.6654 0.4324 0.0940 0.9906 0.0468 0.1547 0.0576 0.6182 0.9954 0.8048 0.1842 0.8711 0.4498 0.8104 0.3860 0.5313 A(:,:,4) = 0.4143 0.7380 0.2589 0.4286 0.1949 0.4761 0.2196 0.3809 0.5016 0.3815 0.2741 0.9400 0.2250 0.9047 0.9829 0.9862 0.1425 0.0772 0.5833 0.3206 0.3210 0.0632 0.4139 0.7289 0.5868 0.7736 0.5324 0.3161 0.4334 0.0550 0.7031 0.6694 0.0109 0.5341 0.4399 0.1195 A(:,:,5) = 0.5985 0.4265 0.0811 0.1229 0.3392 0.7524 0.2603 0.7418 0.4899 0.1817 0.9131 0.3994 0.2359 0.3633 0.3610 0.1934 0.6980 0.0690 0.7655 0.2662 0.3542 0.4334 0.5158 0.1679 0.9395 0.6295 0.1512 0.7503 0.1131 0.1357 0.9663 0.4720 0.1601 0.6951 0.1670 0.1415
A = num2cell(A)
A = 12×3×5 cell array
A(:,:,1) = {[0.3275]} {[0.4565]} {[0.9054]} {[0.7983]} {[0.5975]} {[0.2010]} {[0.2198]} {[0.2999]} {[0.8786]} {[0.9899]} {[0.9124]} {[0.3179]} {[0.9665]} {[0.3451]} {[0.1311]} {[0.2861]} {[0.9911]} {[0.9365]} {[0.9874]} {[0.9247]} {[0.4403]} {[0.8435]} {[0.8488]} {[0.3430]} {[0.0910]} {[0.2928]} {[0.0985]} {[0.0995]} {[0.6732]} {[0.3981]} {[0.2617]} {[0.1184]} {[0.3649]} {[0.8339]} {[0.7366]} {[0.2909]} A(:,:,2) = {[0.0398]} {[0.1426]} {[0.6770]} {[0.9303]} {[0.4939]} {[0.5339]} {[0.0665]} {[0.4595]} {[0.4976]} {[0.0761]} {[0.6740]} {[0.3230]} {[0.3805]} {[0.4837]} {[0.0900]} {[0.8389]} {[0.8596]} {[0.8293]} {[0.9910]} {[0.0807]} {[0.7654]} {[0.4896]} {[0.4105]} {[0.4247]} {[0.6137]} {[0.7339]} {[0.8006]} {[0.4384]} {[0.6656]} {[0.1509]} {[0.2105]} {[0.3942]} {[0.8460]} {[0.5686]} {[0.6290]} {[0.2638]} A(:,:,3) = {[0.0842]} {[0.9096]} {[ 0.2395]} {[0.3705]} {[0.6611]} {[ 0.8899]} {[0.7653]} {[0.4083]} {[ 0.4778]} {[0.9416]} {[0.9301]} {[6.3608e-04]} {[0.8523]} {[0.7219]} {[ 0.8770]} {[0.5199]} {[0.7490]} {[ 0.7645]} {[0.8845]} {[0.4652]} {[ 0.6654]} {[0.4324]} {[0.0940]} {[ 0.9906]} {[0.0468]} {[0.1547]} {[ 0.0576]} {[0.6182]} {[0.9954]} {[ 0.8048]} {[0.1842]} {[0.8711]} {[ 0.4498]} {[0.8104]} {[0.3860]} {[ 0.5313]} A(:,:,4) = {[0.4143]} {[0.7380]} {[0.2589]} {[0.4286]} {[0.1949]} {[0.4761]} {[0.2196]} {[0.3809]} {[0.5016]} {[0.3815]} {[0.2741]} {[0.9400]} {[0.2250]} {[0.9047]} {[0.9829]} {[0.9862]} {[0.1425]} {[0.0772]} {[0.5833]} {[0.3206]} {[0.3210]} {[0.0632]} {[0.4139]} {[0.7289]} {[0.5868]} {[0.7736]} {[0.5324]} {[0.3161]} {[0.4334]} {[0.0550]} {[0.7031]} {[0.6694]} {[0.0109]} {[0.5341]} {[0.4399]} {[0.1195]} A(:,:,5) = {[0.5985]} {[0.4265]} {[0.0811]} {[0.1229]} {[0.3392]} {[0.7524]} {[0.2603]} {[0.7418]} {[0.4899]} {[0.1817]} {[0.9131]} {[0.3994]} {[0.2359]} {[0.3633]} {[0.3610]} {[0.1934]} {[0.6980]} {[0.0690]} {[0.7655]} {[0.2662]} {[0.3542]} {[0.4334]} {[0.5158]} {[0.1679]} {[0.9395]} {[0.6295]} {[0.1512]} {[0.7503]} {[0.1131]} {[0.1357]} {[0.9663]} {[0.4720]} {[0.1601]} {[0.6951]} {[0.1670]} {[0.1415]}
  1 Comment
John D'Errico
John D'Errico on 23 Nov 2022
To expand on what @Torsten said:
A = rand(10);
C = num2cell(A);
whos A C
Name Size Bytes Class Attributes A 10x10 800 double C 10x10 11200 cell
So the cell array, contining the same data, used considerably more memory (14x), to store those same elements.
11200/800
ans = 14
You have an array of size 1440*720*102. Assuming each element is a double, that is
1440*720*102*8/(1024^3)
ans = 0.7879
So a little under 1 gigabyte of RAM, just to store that array. But, as a cell array, of individual elements, you might need as much as
1440*720*102*8/(1024^3)*14
ans = 11.0310
11 gigabytes of RAM to store that cell array, IF you convert each element into one cell.
If you are being mroe efficient, and each cell is itslef more than one element, things might not be so inefficient. But you will still need something on the order of 11 gigabytes of free memory.

Sign in to comment.


Image Analyst
Image Analyst on 23 Nov 2022
You say "cell structure" but it's ambiguous whether you want a structure array or a cell array.
Why on earth would you want to convert it to a cell array? Cell arrays take up way more memory than numerical arrays and are slower and more inefficient. I'd just leave your data as it is.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!