Azzera filtri
Azzera filtri

Need a quick help on storing words according to lengths with struct

1 visualizzazione (ultimi 30 giorni)
Given a wordlist in cell array
wordlist={'blues';'rhyme';'armor';'dinosour';'book';'mail'......};
wordstruct=struct;
%%i am not sure how to proceed however it is organised such that the words are between four to 25, and I would like to do something like this,
wordstruct.4L={book mail ....}
wordstruct.5L={blues rhyme.....}
.
.
.
.
.
wordstruct.26L={whateveritisthatmightexist}
I almost given up on finding the right way to do it this way. Any help is very appreciated!

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 27 Nov 2011
You have to use wordstruct.L4, wordstruct.L5, etc. as '4L','5L' etc. are not valid name.
cellfun('islength',...) and then a for-loop should getting you there.
wordlist={'blues';'rhyme';'armor';'dinosour';'book';'mail'};
clear wordstruct;
Len=cellfun('length',wordlist);
for L=4:26
wordstruct.(['L',num2str(L)])=wordlist(Len==L);
end
  4 Commenti
Fangjun Jiang
Fangjun Jiang il 27 Nov 2011
Sorry, I meant cell2struct(). In fact, it doesn't have to be used. See update.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by