How to save nested cells in mat file

6 ビュー (過去 30 日間)
Sanjana Sankar
Sanjana Sankar 2019 年 8 月 2 日
コメント済み: Sanjana Sankar 2019 年 8 月 19 日
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 件のコメント
Sanjana Sankar
Sanjana Sankar 2019 年 8 月 19 日
26 is not appropriate for me because I'm using german alphabets. Hence it is more than 26. In that case, I cannot use 'a'+1.
Rik
Rik 2019 年 8 月 19 日
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.

サインインしてコメントする。

採用された回答

Rik
Rik 2019 年 8 月 19 日
The code below is probably what you need (or close to it). If letters are used that are not in the letterlist, then an error will occur, because the ind variable will contain a 0.
%all(?) letters used in German:
letterlist=['a':'z' 'A':'Z' ...
char([196 203 207 214 220 223 228 235 239 246 252])];
%generate a library with random entries as an example
lib=cell(1,numel(letterlist));
for n=1:numel(letterlist)
lib{n}=rand(1,63);
end
word='Aalen';
[~,ind]=ismember(word,letterlist);
output=lib(ind);
  1 件のコメント
Sanjana Sankar
Sanjana Sankar 2019 年 8 月 19 日
Thank you Rik! I have to one-hot the letters. But otherwise this code is exactly what I need. I can work with this. :)

サインインしてコメントする。

その他の回答 (1 件)

Mohammad
Mohammad 2019 年 8 月 19 日
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');

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by