how do i remove this error? Function definitions are not permitted in this context.
1 回表示 (過去 30 日間)
古いコメントを表示
xyRange=[1,5]; %// Starting xy range of particles
numP=3; %// Number of particles generated each day
vx=0.6; vy=0.4; %// x and y velocity
X=[]; Y=[]; %// Vectors start out empty
for day=1:10
%// Generate 3 particles and add to end of vectors X and Y
X=[X;randi(xyRange,numP,1)];
Y=[Y;randi(xyRange,numP,1)];
%// Move all the particles
X=X+vx;
Y=Y+vy;
end
plot(X,Y,'kd');
grid on ;
axis([1,50,1,50]);
function [box] = coord(X,Y)
for j = floor(X/5)+1;
k = floor(Y/5);
box = k*10+j;
end
end
0 件のコメント
採用された回答
Thorsten
2015 年 6 月 29 日
You can write it w/o a function, and you don't need the inner for j= ... loop:
for day=1:10
%// Generate 3 particles and add to end of vectors X and Y
X=[X;randi(xyRange,numP,1)];
Y=[Y;randi(xyRange,numP,1)];
%// Move all the particles
X=X+vx;
Y=Y+vy;
end
plot(X,Y,'kd');
grid on ;
axis([1,50,1,50]);
j = floor(X/5)+1;
k = floor(Y/5);
box = k*10+j;
end
2 件のコメント
Adam
2015 年 6 月 29 日
You should give completely new questions their own thread really rather than tagging them onto a comment of an answer.
その他の回答 (1 件)
James Tursa
2015 年 6 月 29 日
You have your sub function "coord" defined inside your for loop. Move it outside your for loop.
2 件のコメント
Adam
2015 年 6 月 29 日
also if that is a script you need to turn the whole thing into a function in order to define subfunctions.
参考
カテゴリ
Help Center および File Exchange で Calendar についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!