How to store this type of data with unknown number of them?
5 views (last 30 days)
Show older comments
I have a N by 3 column data, each row, I need to store some additional information like the below:
empty []
[1, 2, 31]
[45]
[89, 37]
These are the station numbers from another file.
What's the best way to store these values, to have the smallest footprint (file size)? Thanks.
0 Comments
Accepted Answer
Walter Roberson
on 10 Jun 2025
Let us experiment
N = 100;
A = randi(9,N,1);
B = randi(9,N,1);
C = randi(9,N,1);
D = cell(N,1);
for K = 1 : N
D{K} = randi(99,1,randi(5,1));
end
T1 = {A, B, C, D};
T2 = table(A, B, C, D);
T3 = table([A,B,C], D);
T4 = cell(N,1);
for K = 1 : N
T4{K} = [A(K), B(K), C(K), D{K}];
end
whos T1 T2 T3 T4
save T1.mat T1
save T2.mat T2
save T3.mat T3
save T4.mat T4
ls -l T*.mat
So the smallest memory size is a cell array of rows of variable size, with the first three entries in each row being a 1 x 3 row extract and the remaining entries in the row being variable entries.
Note that this is not the best storage arrangement if you are needing to extract one of the three columns from it.
The smallest file size is also the same cell array just mentioned. But the difference in file size compared to the 1 x 4 cell array is quite small; one suspects that the difference might almost be accidental, with it being plausible that with different data that the 1 x 4 cell array just might come out slightly smaller.
The versions T1 and T2 are suitable for the case where the datatypes of everything might be different.
The version T3 is suitable for the case where the datatypes of the N x 3 are all the same but the datatypes of the variable data might be different.
The version T4 depends on all of the datatypes being the same.
More Answers (0)
See Also
Categories
Find more on PHY Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!