How i can add a car image to yellow boxes and at y coordinate 4,5,6 a road image? (Sorry i have low vocabulary of English).
close all;
clc;
loop = 200;
r = 9;
c = 20;
carOccuranceMidWay = 0.05; %0-1
carMoveMidWay = 0.4; %0-1
carMoveFastWay = 0.7; %0-1
carMoveSlowWay = 0.2; %0-1
% define grid
x = zeros(r, c);
figure;
% x(5,1) = 1;
%
for i = 1:loop
for j = 1:c – 1
if(rand <= carOccuranceMidWay && x(5,1) == 0)
x(5,1) = 1;
end
% car exit from highway
if(x(5,c – 1) == 1) %For centerline
x(5,c – 1) = 0;
end
if(x(4,c – 1) == 1) %For FastLane
x(4,c – 1) = 0;
end
if(x(6,c – 1) == 1) %For SlowLane
x(6,c – 1) = 0;
end
% car move
if(x(5, j) == 1 && x(5, j + 1) == 0) % transition rules #1 for centerlane movement
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(5, j + 1) = 1;
end
end
if(x(5, j) == 1 && x(5, j + 1) == 1 && x(4,j)== 0) % transition rules #2 for transition to FastLane
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(4, j ) = 1;
end
end
if(x(5, j) == 1 && x(5, j + 1) == 1 && x(6,j)== 0) % transition rules #3 for transition to SlowLane
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(6, j ) = 1;
end
end
if(x(6, j) == 1 && x(6, j + 1) == 0) % transition rules #4 for SlowLane movement
if(rand <= carMoveSlowWay)
x(6, j ) = 0;
x(6, j + 1) = 1;
end
end
if(x(4, j) == 1 && x(4, j + 1) == 0) % transition rules #5 for FastLane movement
if(rand <= carMoveFastWay)
x(4, j ) = 0;
x(4, j + 1) = 1;
end
end
% Animate
clf; % Clear figure
imagesc(x);
% Display grid
pause(0.01);
end % Pause for 0.01 s
endclose all;
clc;
loop = 200;
r = 9;
c = 20;
carOccuranceMidWay = 0.05; %0-1
carMoveMidWay = 0.4; %0-1
carMoveFastWay = 0.7; %0-1
carMoveSlowWay = 0.2; %0-1
% define grid
x = zeros(r, c);
figure;
% x(5,1) = 1;
%
for i = 1:loop
for j = 1:c – 1
if(rand <= carOccuranceMidWay && x(5,1) == 0)
x(5,1) = 1;
end
% car exit from highway
if(x(5,c – 1) == 1) %For centerline
x(5,c – 1) = 0;
end
if(x(4,c – 1) == 1) %For FastLane
x(4,c – 1) = 0;
end
if(x(6,c – 1) == 1) %For SlowLane
x(6,c – 1) = 0;
end
% car move
if(x(5, j) == 1 && x(5, j + 1) == 0) % transition rules #1 for centerlane movement
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(5, j + 1) = 1;
end
end
if(x(5, j) == 1 && x(5, j + 1) == 1 && x(4,j)== 0) % transition rules #2 for transition to FastLane
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(4, j ) = 1;
end
end
if(x(5, j) == 1 && x(5, j + 1) == 1 && x(6,j)== 0) % transition rules #3 for transition to SlowLane
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(6, j ) = 1;
end
end
if(x(6, j) == 1 && x(6, j + 1) == 0) % transition rules #4 for SlowLane movement
if(rand <= carMoveSlowWay)
x(6, j ) = 0;
x(6, j + 1) = 1;
end
end
if(x(4, j) == 1 && x(4, j + 1) == 0) % transition rules #5 for FastLane movement
if(rand <= carMoveFastWay)
x(4, j ) = 0;
x(4, j + 1) = 1;
end
end
% Animate
clf; % Clear figure
imagesc(x);
% Display grid
pause(0.01);
end % Pause for 0.01 s
end close all;
clc;
loop = 200;
r = 9;
c = 20;
carOccuranceMidWay = 0.05; %0-1
carMoveMidWay = 0.4; %0-1
carMoveFastWay = 0.7; %0-1
carMoveSlowWay = 0.2; %0-1
% define grid
x = zeros(r, c);
figure;
% x(5,1) = 1;
%
for i = 1:loop
for j = 1:c – 1
if(rand <= carOccuranceMidWay && x(5,1) == 0)
x(5,1) = 1;
end
% car exit from highway
if(x(5,c – 1) == 1) %For centerline
x(5,c – 1) = 0;
end
if(x(4,c – 1) == 1) %For FastLane
x(4,c – 1) = 0;
end
if(x(6,c – 1) == 1) %For SlowLane
x(6,c – 1) = 0;
end
% car move
if(x(5, j) == 1 && x(5, j + 1) == 0) % transition rules #1 for centerlane movement
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(5, j + 1) = 1;
end
end
if(x(5, j) == 1 && x(5, j + 1) == 1 && x(4,j)== 0) % transition rules #2 for transition to FastLane
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(4, j ) = 1;
end
end
if(x(5, j) == 1 && x(5, j + 1) == 1 && x(6,j)== 0) % transition rules #3 for transition to SlowLane
if(rand <= carMoveMidWay)
x(5, j ) = 0;
x(6, j ) = 1;
end
end
if(x(6, j) == 1 && x(6, j + 1) == 0) % transition rules #4 for SlowLane movement
if(rand <= carMoveSlowWay)
x(6, j ) = 0;
x(6, j + 1) = 1;
end
end
if(x(4, j) == 1 && x(4, j + 1) == 0) % transition rules #5 for FastLane movement
if(rand <= carMoveFastWay)
x(4, j ) = 0;
x(4, j + 1) = 1;
end
end
% Animate
clf; % Clear figure
imagesc(x);
% Display grid
pause(0.01);
end % Pause for 0.01 s
end highway simulation, how to add a car to a box, how to add a car image to a moving plot in matlab, matlab car code MATLAB Answers — New Questions