Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 ne rollowing function simulates a random walk, using a matrix to store the random walk as it progresses. To begin with all elements are

1ne rollowing function simulates a "random walk," using a matrix to store the random walk as it progresses. To begin with all elements are initialized to 1. Then, the "middle" element is chosen to be the starting point for the random walk; a 2 is placed in that element. (Note: these numbers will eventually represent colors.) Then, from this starting point another element next to the current one is chosen randomly and the color stored in that element is incremented; this repeats until one of the edges of the matrix is reached. Every time an element is chosen for the next element, it is done randomly by either adding or subtracting one to/from each coordinate (x and y), or leaving it alone. The resulting matrix that is returned is an n by n matrix.
function walkmat = ranwalk (n)
walkmat = ones (n);
x=flr(n2);
y=flr(n2);
color =2;
walkmat (x,x)= color;
while x=1 && x=n && y=1 && y=n
x=x+randi([-11]);
y=y+ randi ([-11]);
color = color +1 ;
walkmat (x,y)=mod(color,65);
end
end
You are to write a script that will call this function twice (once passing 8 and once passing 100) and display the resulting matrices as images side-by-side. Your script must create a custom colormap that has 65 colors; the first is white and the rest are from the colormap jet. For example, the result may look like Figure 14.33(Note that with the 88 matrix the colors are not likely to get out of the blue range, but with 10000 it cycles through all colors multiple times until an edge is reached):
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

On average, what is the largest revenue component measure?

Answered: 1 week ago

Question

What is managements expected profit margin for each product?

Answered: 1 week ago