Q:

Write a function wordscramble that will receive a word in a string as an input argument. It will then randomly scramble the letters and return the result. Here is an example of calling the function:

0

 Write a function wordscramble that will receive a word in a string 

as an input argument. It will then randomly scramble the letters and 

return the result. Here is an example of calling the function:

>> wordscramble('fantastic')

ans =

safntcait

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

wordScramble.m

function outword = wordScramble(inword)

% Randomly scramble the letters in a word

% Format of call: wordScramble(word)

% Returns string with same length as input

% string but with characters randomly scrambled

len = length(inword);

% Put random index in first element

indvec = zeros(1,len);

indvec(1) = randi([1 len]);

% Make sure every index only used once

for i = 2:len

 ran = randi([1 len]);

 while any(indvec(1:i-1)== ran)

 ran = randi([1,len]);

 end

 indvec(i) = ran;

end

outword = inword(indvec);

end

Massive amounts of temperature data have been accumulated and 

stored in files. To be able to comb through this data and gain insights 

into global temperature variations, it is often useful to visualize the 

information. 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now