Write a Matlab function Iamrandom that receives two integers
size, iterations and a word name (array of characters) as inputs
and that:
• generates iterations times a random word of length size;
• check for each of them whether the input name appears in the
generated random word, using your function mychartfindrec;
• counts the number of successes, i.e., the number of times the
answer is YES in the previous experiment.
function [result] = mychartrec(x, y)
n = length(x);
m = length(y);
if n > m
[result] = false;
return
else
for k = 1:m-n+1
if mychartest(x,
y(k:k+n-1))
[result] =
true;
return
end
end
end
end
this is what I have so far, but it's not actually counting the
number of times a name is generated
function result = iamrandom(size, iterations, name)
result = 0;
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
r = randi(26, iterations, size);
words = alphabet(r);
disp(words)
for i = 1:iterations
word = words(i);
if mychartrec(name, word) == true
result = result + 1;
disp(word)
end
end
end
Write a Matlab function Iamrandom that receives two integers size, iterations and a word name (array of characters) as i
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am