我尝试使用MATLAB对汽车和信号进行交通模拟。信号将控制某个时间有多少辆汽车。我刚刚开始这个功能。基本上我现在所做的就是试图在路上生成汽车图像。代码如下所示,注释解释了代码特定部分的用途。然而,“#imshow”中出现了一些问题。功能。有人可以指出我犯的错误吗? (所有文件都放在当前工作目录中)
因为我不能在这里附上照片。我已将它们上传到Dropbox上,链接如下所示。
function [ output_args ] = drawcars( ncars )
%drawcars takes the number of cars at a timestep & shows an image for each car on the road.
image(imread('road.jpg')); %load the road
% plot the number of cars
hold on;
for x=1:50:ncars*50
ih = image(imread('car.png'));
ih.XData = [x+5 x+50]; %to plot cars adjacent to one and another
ih.YData = [100 50]; %same line on the Y axis.
end
drawnow;
hold off;
pause(1); %wait for one second.
end
编辑:好的,我已经修复了图像处理工具箱。它没有提供所需的输出。它只会在car.png
的左上角显示一个road.jpg
。
命令行显示drawcars(5)
。
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2
Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details.
> In drawcars at 12
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2
Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details.
> In drawcars at 12
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2
Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details.
> In drawcars at 12
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2
Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details.
> In drawcars at 12
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2
Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details.
> In drawcars at 12