How can I store large strings in an array?
8 次查看(过去 30 天)
显示 更早的评论
Dear Matlab community,
I need to store large strings coming from fread in an array. With a conventional array, this fails with the "Out of memory." error.
I am not really into this topic but for handling large data sets I found two possible solutions which both do apparently not work for my situation:
1) Using matfile: This works great for arrays of numbers, but trying to use strings with a command like
matfileObj.stringArray(i) = char(fread(...));
results in the error "... is of type string. To use ... load the entire variable." However, I am not able to do this for the above-mentioned lack of memory.
2) Using tall: Unfortunately, the file that I work on is in a very ugly binary format that I think can't connect with a datastore. I could, however, initialise a string array of the needed length and generate a tall array from this. But now it seems I can't replace the initialisation strings with the real data; even the command
tallStringArray(i) = "";
fails with "For A(m,n,...) = B, m must be either a colon (:) or a tall logical vector." So apparently, I can't change single entries in the tall array.
Do you have any idea how I can store these large strings?
Many thanks for sharing your thoughts,
Ed
3 个评论
John D'Errico
2020-3-24
You have large strings of varying sizes? Then learn about cell arrays, which can store them without wasting space because some are larger than others. If you use a regular array, then the array needs to be rectangular, so is far less effcieitn in terms of memory.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!