subject

Step 1 : grab the file Execute your script after adding a proper load() call then check your workspace. The code should run without any output, and within your workspace you can now see all the variables stored in the .mat file.
step 2 : display the initial grid
In this step we want to call the provided function displayGrid() for the first time. The function takes a single input, a grid, so we send the current grid as the only function argument. After our function call we should pause for 2 seconds, allowing the figure and other graphics to load prior to any future animation.
step 3: the percolate function
The goal of the percolate function is to move water from any spot in the grid that currently contains water to a set of its neighbors. The function performs a single iteration of percolation across the entire grid. The function name is percolate and it has a single input and a single output. The input is the 2D array (the grid) in its current state. The single output is a 2D array containing the new grid after a single iteration of percolation has occurred. This output/return value should be assigned into the grid in the main scripting area when the function is called to overwrite the current grid, thus completing the update.
step 4 : Call the percolate Function & Display Updated Grid
Once the percolate function is completed in part or in totality, you will need to call it within the main scripting area to execute the function and acquire the return value to update the grid variable. The provided displayGrid() function can be used to help visually evaluate the percolate function's functionality.
displayGrid() should be called in your main scripting area (completed in Step 2) before the percolate function is called and then again after the percolate function returns and updates the grid variable.
After this second call, pause just like after the first, but this time for 0.1 seconds.
At this point you should be able to reproduce the initial, 1st, and 2nd grids in the above table by calling percolation twice and displaying the grid in a new figure each time. Alternatively if you pause and use a single figure then you will see a short 3 step animation sequence.
step 5 : add the amination loop
The final coding step is to encompass your percolate(), displayGrid(), and pause() calls into an animation loop. This loop should continue going as long as the endPoint is not in the WATER state (it's value is not equal to the value of WATER). The endPoint variable was discussed in Step 1.
starter code :
close all;
clear;
% TODO: Step 1
% TODO: Define these states in every function you write.
% Then use the names instead of the numeric literal values.
% Three potential states of the grid
WATER = 1;
IMPERMEABLE = 0;
PERMEABLE = 2;
% TODO: Complete Step 2
% TODO: Complete step 4 and then once complete, complete step 5.
% TODO: Complete Step 3
function displayGrid(grid)
% Displays the provided 2D array using a specific colormap
% INPUTS: grid - the 2D array representating the current percolation state
% OUTPUTS: displays the 2D array using imagesc
colormap colorcube;
imagesc(grid)
axis off;
end
can test with the following code :
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Import the file
newData1 = load('-mat', fileToRead1);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, kieraweems2034
Communication is the exchange of information. true false
Answers: 2
image
Computers and Technology, 22.06.2019 23:00, brookerebman15
Which type of tab stop is most for weights and measurements?
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, la200564
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
image
Computers and Technology, 24.06.2019 00:00, Amrinderkhattra
Visualizing a game of β€œtag” to remember the meaning of contagious
Answers: 3
You know the right answer?
Step 1 : grab the file Execute your script after adding a proper load() call then check your works...

Questions in other subjects:

Konu
Mathematics, 04.05.2021 14:40
Konu
English, 04.05.2021 14:40