Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% test
- clear
- clc
- clf
- moves = {};
- % Create a 2D array of size 8x8 containing zeros
- a = zeros(8, 8);
- % Set the pixel at position (3,3) to 1
- a(3, 3) = 1;
- % Determine the size of the matrix a
- [y_len, x_len] = size(a);
- % Nested for loop to iterate through all y and x coordinates
- for y = 1:y_len
- for x = 1:x_len
- % Check if the value at a(y,x) is equal to 1 (gas particle exists)
- if a(y, x) == 1
- % Choose a random number between 0 and 3
- %r = floor(rand*3.9999); % rand gives value between 0 and 1 so multiplying by close to 3.9999 will give values from 0 to 3.9999 which when using float will round to 0 to 3
- r = 1;
- moves = [moves,r];
- % Move the gas particle based on the random number
- if r == 0
- % Move up
- a(y-1, x) = 1;
- a(y, x) = 0;
- disp('Moving particle up')
- break
- elseif r == 1
- % Move down
- a(y+1, x) = 1;
- a(y, x) = 0;
- disp('Moving particle down')
- break
- elseif r == 2
- % Move left
- a(y, x-1) = 1;
- a(y, x) = 0;
- disp('Moving particle left')
- break
- elseif r == 3
- % Move right
- a(y, x+1) = 1;
- a(y, x) = 0;
- disp('Moving particle right')
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement