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:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:7| Question number:34.7
All Answers
total answers (1)
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