Condense word search code

3 views (last 30 days)
Nydea Ortega
Nydea Ortega on 15 Apr 2019
I have pasted our word search code in hopes that someone will be able to find ways to condense our code since it takes about 45 seconds to load. In our code, we have the words set only going vertical since we couldn't find a way to place them horizontally and vertically without a lot of overlapping. If you have any advice, it will be appreciated.
clear all
clc
close all
%Creates the grid
xlim([0 20]);
ylim([0 20]);
grid('on');
% creates alphabet array
alpha26 = {'A','B','C','D','E','F','G','H','I','J','K','L',...
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
%First Word
word1 = 'ALPACA';
%Second Word
word2 = 'ARMADILLO';
%Third Word
word3 = 'BABOON';
%Fourth Word
word4 = 'SNAKE';
%Fifth Word
word5 = 'VULTURE';
%Sixth Word
word6 = 'PENGUIN';
%Seventh Word
word7 = 'LION';
%Eigth Word
word8 = 'PORCUPINE';
%Ninth Word
word9 = 'REINDEER';
%Tenth Word
word10 = 'HIPPOPOTAMUS';
%For word 1
x = randi(20)-0.5;
y = randi(15) - 0.5;
%For word 2
x1 = randi(20) - 0.5;
y1 = randi(12) - 0.5;
%For word 3
x2 = randi(20) - 0.5;
y2 = randi(15) - 0.5;
%For word 4
x3 = randi(20) -0.5;
y3 = randi(16) - 0.5;
%For word 5
x4 = randi(20) - 0.5;
y4 = randi(14) - 0.5;
%For word 6
x5 = randi(20) - 0.5;
y5 = randi(14) - 0.5;
%For word 7
x6 = randi(20) - 0.5;
y6 = randi(17) - 0.5;
%For word 8
x7 = randi(20) - 0.5;
y7 = randi(12) - 0.5;
%For word 9
x8 = randi(20) - 0.5;
y8 = randi(13) - 0.5;
%For word 10
x9 = randi(20) - 0.5;
y9 = randi(9) - 0.5;
for k = 0:length(word1)-1
a = [x,y+k];
end
for l = 0:length(word2)-1
b = [x1,y1+l];
end
for m = 0:length(word3)-1
c = [x2,y2+m];
end
for n = 0:length(word4)-1
d = [x3,y3+n];
end
for o = 0:length(word5)-1
e = [x4,y4+o];
end
for p = 0:length(word6)-1
f = [x5,y5+p];
end
for q = 0:length(word7)-1
g = [x6,y6+q];
end
for r = 0:length(word8)-1
h = [x7,y7+r];
end
for s = 0:length(word9)-1
ii = [x8,y8+s];
end
for t = 0:length(word10)-1
jj = [x9,y9+t];
end
while x == x1
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x2
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x3
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x4
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x5
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x6
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x7
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x8
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x == x9
if x == 19.5
x = x - 1.5;
elseif x == 0.5
x = x + 1.5;
elseif x ~= 0.5 && 19.5
x = randi(20) - 0.5;
end
end
while x1 == x
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x2
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x3
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x4
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x5
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x6
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x7
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x8
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x1 == x9
if x1 == 19.5
x1 = x1 - 1.5;
elseif x1 == 0.5
x1 = x1 + 1.5;
elseif x1 ~= 0.5 && 19.5
x1 = randi(20) - 0.5;
end
end
while x2 == x
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x1
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x3
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x4
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x5
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x6
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x7
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x8
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x2 == x9
if x2 == 19.5
x2 = x2 - 1.5;
elseif x2 == 0.5
x2 = x2 + 1.5;
elseif x2 ~= 0.5 && 19.5
x2 = randi(20) - 0.5;
end
end
while x3 == x
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x1
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = 3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x2
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x4
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x5
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x6
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x7
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x8
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x3 == x9
if x3 == 19.5
x3 = x3 - 1.5;
elseif x3 == 0.5
x3 = x3 + 1.5;
elseif x3 ~= 0.5 && 19.5
x3 = randi(20) - 0.5;
end
end
while x4 == x
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x1
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x2
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x3
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x5
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x6
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x7
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x8
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x4 == x9
if x4 == 19.5
x4 = x4 - 1.5;
elseif x4 == 0.5
x4 = x4 + 1.5;
elseif x4 ~= 0.5 && 19.5
x4 = randi(20) - 0.5;
end
end
while x5 == x
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x1
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x2
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x3
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x4
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x6
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x7
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x8
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x5 == x9
if x5 == 19.5
x5 = x5 - 1.5;
elseif x5 == 0.5
x5 = x5 + 1.5;
elseif x5 ~= 0.5 && 19.5
x5 = randi(20) - 0.5;
end
end
while x6 == x
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x1
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x2
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x3
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x4
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x5
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x7
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x8
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x6 == x9
if x6 == 19.5
x6 = x6 - 1.5;
elseif x6 == 0.5
x6 = x6 + 1.5;
elseif x6 ~= 0.5 && 19.5
x6 = randi(20) - 0.5;
end
end
while x7 == x
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x1
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x2
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x3
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x4
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x5
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x6
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x8
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x7 == x9
if x7 == 19.5
x7 = x7 - 1.5;
elseif x7 == 0.5
x7 = x7 + 1.5;
elseif x7 ~= 0.5 && 19.5
x7 = randi(20) - 0.5;
end
end
while x8 == x
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x1
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x2
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x3
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x4
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x5
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x6
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x7
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x8 == x9
if x8 == 19.5
x8 = x8 - 1.5;
elseif x8 == 0.5
x8 = x8 + 1.5;
elseif x8 ~= 0.5 && 19.5
x8 = randi(20) - 0.5;
end
end
while x9 == x
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x1
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x2
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x3
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x4
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x5
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x6
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x7
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
while x9 == x8
if x9 == 19.5
x9 = x9 - 1.5;
elseif x9 == 0.5
x9 = x9 + 1.5;
elseif x9 ~= 0.5 && 19.5
x9 = randi(20) - 0.5;
end
end
for i = 1:20
for j = 1:20
ws{i,j} = alpha26{randi(26)};
end
end
%Word 1
for mo = y + 0.5:y + length(word1)-0.5
ws{(x+0.5),mo} = ('');
%Word 2
for mo1 = y1 + 0.5:y1 + length(word2)-0.5
ws{(x1+0.5),mo1} = ('');
%Word 3
for mo2 = y2 + 0.5:y2 + length(word3)-0.5
ws{(x2+0.5),mo2} = ('');
%Word 4
for mo3 = y3 +0.5:y3 + length(word4)-0.5
ws{(x3+0.5),mo3} = ('');
%Word 5
for mo4 = y4 + 0.5: y4 +length(word5) -0.5
ws{(x4+0.5),mo4} = ('');
%Word 6
for mo5 = y5 + 0.5: y5 +length(word6) -0.5
ws{(x5+0.5),mo5} = ('');
%Word 7
for mo6 = y6 + 0.5: y6 +length(word7) -0.5
ws{(x6+0.5),mo6} = ('');
%Word 8
for mo7 = y7 + 0.5: y7 +length(word8) -0.5
ws{(x7+0.5),mo7} = ('');
%Word 9
for mo8 = y8 + 0.5: y8 +length(word9) -0.5
ws{(x8+0.5),mo8} = ('');
%Word 10
for mo9 = y9 + 0.5: y9 +length(word10) -0.5
ws{(x9+0.5),mo9} = ('');
end
end
end
end
end
end
end
end
end
end
% puts random letters in the grid
for p = 1:20
for n = 1:20
te1 = text(p-0.5, n-0.5 , ws{p,n}, ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'k')
end
end
for p=1:20
for n = 1:10
te1 = text(p-0.5, n-0.5 , ws{p,n}, ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'k')
end
end
% puts letters of first word in the grid
for p = 1 %1 row
for n = 1:length(word1) % 6
te1 = text(x,y,word1(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y = y + 1;
end
end
%Placing word 2 into the grid
for p = 1 %1 row
for n = 1:length(word2) %9
te1 = text(x1,y1,word2(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y1 = y1 + 1;
end
end
%Placing word 3 into the grid
for p = 1 %1 row
for n = 1:length(word3) %6
te1 = text(x2,y2,word3(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y2 = y2 + 1;
end
end
%Placing word 4 into the grid
for p = 1 %1 row
for n = 1:length(word4) %5
te1 = text(x3,y3,word4(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y3 = y3 + 1;
end
end
%Placing word 5 into the grid
for p = 1 %1 row
for n = 1:length(word5) %5
te1 = text(x4,y4,word5(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y4 = y4 + 1;
end
end
%Placing word 6 into the grid
for p = 1 %1 row
for n = 1:length(word6) %5
te1 = text(x5,y5,word6(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y5 = y5 + 1;
end
end
%Placing word 7 into the grid
for p = 1 %1 row
for n = 1:length(word7) %5
te1 = text(x6,y6,word7(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y6 = y6 + 1;
end
end
%Placing word 8 into the grid
for p = 1 %1 row
for n = 1:length(word8) %5
te1 = text(x7,y7,word8(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y7 = y7 + 1;
end
end
%Placing word 9 into the grid
for p = 1 %1 row
for n = 1:length(word9) %5
te1 = text(x8,y8,word9(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y8 = y8 + 1;
end
end
%Placing word 10 into the grid
for p = 1 %1 row
for n = 1:length(word10) %5
te1 = text(x9,y9,word10(p,n), ...
'fontsize', 20, 'horizontalalignment', 'center');
set(te1, 'color', 'g')
y9 = y9 + 1;
end
end

Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!