Compare two numeric cell arrays
显示 更早的评论
I have two huge cells, a dictionary and a set of possible hands in scrabble. I want to compare the two and find what arrays match
myAletters = ['D','I','R','N','E','E','P'];
myAletters = upper(myAletters);
myAletters = int8(myAletters);
myAletters = myAletters-64;
hand_count=0;
for i=1:length(myAletters)
hand_interim_combination=nchoosek(myAletters,i);
for j=1:length(hand_interim_combination(:,1))
hand_interim_permutation=perms(hand_interim_combination(j,:));
for k=1:length(hand_interim_permutation(:,1))
hand_count=hand_count+1;
hand{hand_count}=hand_interim_permutation(k,:);
end
end
end
end
load('myDict.mat');
word_plays=ismember(hand,myDict);
Ismember won't work because it has to be strings, going one by one won't work because it takes too long. Wat do?
2 个评论
Andrei Bobrov
2017-1-17
Please attach your file myDict.mat.
"going one by one won't work because it takes too long. Wat do?"
Stop ignoring mlint messages in the Editor. There is already one message in your code telling you that the way you have written it is going to be slow. The message even tells you how to solve this issue:

Also note that the following code does not create an array of separate characters, because [] is a concatenation operator, not a list operators as many beginners think:
>> myAletters = ['D','I','R','N','E','E','P']
myAletters =
DIRNEEP
That code is therefore equivalent to simply writing this:
>> myAletters = 'DIRNEEP'
myAletters =
DIRNEEP
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!