How to save nested cells in mat file
Show older comments
I want to save data in such a way that a cell holds another cell array.
My main table will consist of cells, each of which will hold 24 cell arrays of size 1X63. How to save data in such a manner?
The idea is that I am encoding a words with numbers
For example. If my word is Aalen, A = 1x63 vector, a = 1x63 vector, l = 1x63 vector, e=1x63 vector, n=1x63 vector.
So for each word in my list, I waant to save a vector for each letter in the word.
3 Comments
Rik
on 2 Aug 2019
It sounds like you need a 1x24 or 24x1 element cell array, with each containing a 1x63 double array. Why not 26 by the way? Then you would have a cell element for each letter. And is the vector for 'A' the same as for 'a'?
If you convert your char to double, you can easily use them as indices:
%generate a library random as an example
lib=cell(1,26);
for n=1:26
lib{n}=rand(1,63);
end
word='Aalen';
%convert to cell array
ind=lower(word)-'a'+1;%convert to lowercase and map 'a' to 1
output=lib(ind);
Sanjana Sankar
on 19 Aug 2019
Rik
on 19 Aug 2019
Something like this will still work. You will either have a library with a lot of empty cells, or you need to have an extra lookup table step.
Accepted Answer
More Answers (1)
Mohammad
on 19 Aug 2019
You can create nested cell in following manner:
N = 5;
A = {cell(1,N)};
for k = 1:N
A{k} = rand(1,63);
end
You can also convert a string into a cell array of letters the following way:
S = num2cell('Aalen');
Categories
Find more on Data Type Conversion 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!