Hello,
I have a 1x11 cell and want to save some columns of the cell (from 1st column to 8th column only) into a MAT-file.
data =
columns 1 through 4
[21350235x8 char] [21350235x6 char] [21350235x6 char] [21350235x1 int32]
columns 5 through 8
[21350235x64 char] [21350235x10 char] [21350235x1 int32] [21350235x1 int32]
columns 9 through 11
{21350235x1 cell} {21350235x1 cell} {21350235x1 cell}
Columns 9 ~ 11 consist of character strings of variable lengths containing unicode texts. If I try to save them in MAT-file, MATLAB requires to use -v7.3 switch. The saved MAT file has too large size, I want eliminate columns 9 through 11 instead.
Could you please tell me how to do it?
Many thanks!

8 commentaires

Geoff Hayes
Geoff Hayes le 22 Fév 2015
Yongmin - do you want to access the first 8 columns only or save them to a file or something else? Please clarify what you intend to do with the eight columns.
Yongmin
Yongmin le 22 Fév 2015
Hello Geoff, What I want to do is to save 8 columns of a cell array to a file. Thanks for your comment.
Geoff Hayes
Geoff Hayes le 22 Fév 2015
What can you tell us about each column in the cell array? Are they strings, numbers, arrays, matrices? Do they have the same data type or different? Are they of the same dimension or different? Do you want to save the data to a text file or a binary file or a mat file? Please include all relevant information.
Yongmin
Yongmin le 22 Fév 2015
According to your comment, I revised my question. If I need to clarify further, please let me know. Many thanks!
Try removing the 9th to 11th columns of data as
data = data{1:8};
and then save the array as before.
Yongmin
Yongmin le 24 Fév 2015
Thanks again for your answer.
By the way, the command you taught saves only column 1. Thus the size of new data is [21350235x8 char].
Would you please tell me how to get columns 1 to 8 together?
There was a typo in Geoff's comment, it should be
data = data(1:8);
instead.
Titus
Yongmin
Yongmin le 24 Fév 2015
Thanks Geoff and Titus. I tried to accessing each element of the cell by data{1}, data{2}, and so on. Anyhow your comment were very helpful.

Connectez-vous pour commenter.

 Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 24 Fév 2015
Hi,
you should be able to index into data without destroying data or doing copies:
dataTruncated = data(1:8);
save someFile.mat dataTruncated
If you prefer to have the data in the file called "data", then cut of the last cells as Geoff suggested and then save ...
Titus

10 commentaires

Yongmin
Yongmin le 24 Fév 2015
Thanks a lot Titus. Your answer and clarification are helpful much.
Yongmin
Yongmin le 24 Fév 2015
Although I get a truncated array having columns 1 through 8, I cannot still save the cell array dataTruncated. When I use the second command, MATLAB saves an empty array. Is there any limit to save variables?
Titus Edelhofer
Titus Edelhofer le 24 Fév 2015
Strange... Any error message you get?
Yongmin
Yongmin le 24 Fév 2015
Modifié(e) : Yongmin le 24 Fév 2015
No, I don't have any message. In fact, I saved similar types of cell arrays well. However, I have a problem with the cell dataTruncated.
For your information, dataTruncated has a size of 6 GB approximately.
Titus Edelhofer
Titus Edelhofer le 24 Fév 2015
It could be just about being too large. Could you try with data(1:2) which is much smaller?
Titus Edelhofer
Titus Edelhofer le 24 Fév 2015
You will need -v7.3 if the data is larger than 2GB ...
Yongmin
Yongmin le 24 Fév 2015
Yes, I guess your answer is correct. I can save dataTruncated having smaller sizes but I cannot save dataTruncated with columns 5 and 6 having large sizes.
Thank you!
Yongmin
Yongmin le 24 Fév 2015
I see. I can save dataTruncated with the option, -v7.3.
In this case the MAT file can be too large. Is there any way to reduce the size of MAT file?
Thanks a lot for your kind answer!!
Titus Edelhofer
Titus Edelhofer le 25 Fév 2015
Hi,
what I would do is to write two small helper functions "myload" and "mysave", that e.g. saves individual entries of your cell array to individual .mat files (maybe zip them together if you prefer to have one file), and for load to the opposite of reading the individual files.
Titus
Yongmin
Yongmin le 2 Mar 2015
Thanks a lot for your idea, Titus. I will follow your suggestion.
Regards, Yongmin

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by