comparing to string array

2 次查看(过去 30 天)
xRobot
xRobot 2019-11-22
编辑: per isakson 2019-11-24
Hello, I have a large string array with many four letter words called "words". I also have a matrix of char that is has been scrambled called "scrambled"(it is a block of letters). I am attempting to sort all possible combinations of the char matrix and compare them to my list to see if there any possible combinations of four letters that match a word in my list. I have tried a couple of things that did not work. I am new to matlab so I am having trouble with the process. Below are examples of the variables I am working with. Any advice is greatly appreciated. Thanks in advance!
words = ["make" "hope" "list" "home"]
scrambled =
kame
stit
abnaa
  7 个评论
xRobot
xRobot 2019-11-23
What would "thisword" and "available_letters" refer to? Is thisword referring to the remaining letters in the block?
Walter Roberson
Walter Roberson 2019-11-23
can_form_a_word = false;
for thisword = words(:).'
if all(ismember(thisword{1}, letters_remaining_in_block))
can_form_a_word = true;
break;
end
end
if ~can_form_a_word
disp('No more word soup for you!')
end

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-11-22
ScS = string(scrambled);
[present, index] = ismember(ScS, words) ;
present will be a logical vector. Each location that is true will have a corresponding value in index that will reflect the position inside words that scrambled came from. For example if present(2) is true and index(2) is 7 then ScS(2) is words(7)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by