1-方向のある1行に対して次のコードを試してください。
%Initial line information
startPoint = [20 50] ;
direction = [4 3] ;
lineLength = 100;
%Initialize line points with zeros
x = zeros(lineLength);
y = zeros(lineLength);
% Update line points
for i = 1 : lineLength
x(i) = startPoint(1) + direction(1) * i;
y(i) = startPoint(2) + direction(2) * i;
end
%Plot the line
plot( y , x ,'r.');
2-そして、すべてのポイントで方向を変更したい場合は、
次のコードを使用します。
%Initial line values
startPoint = [20 50] ;
lineLength = 100;
%create random direction vector
randomMax = 100;
direction = randi(randomMax,lineLength,2);
%Initialize line points with zeros
x = zeros(lineLength);
y = zeros(lineLength);
%set first points
x(1) = startPoint(1);
y(1) = startPoint(2);
% Update line points accumulating on previous point
for i = 2 : lineLength
x(i) = x(i - 1) + direction(i,1) * i;
y(i) = y(i - 1) + direction(i,2) * i;
end
%Plot the line
plot( y , x ,'r.');
3-それぞれ方向が異なるさまざまな行に対して、次のコードを使用します。
%Initial line values
startPoint = [20 50] ;
lineLength = 100;
%create random the 100 directions vector
randomMax = 100;
directions = randi(randomMax,lineLength,2);
%Initialize line points with zeros
x = zeros(lineLength,100);
y = zeros(lineLength,100);
%set first points
x(1) = startPoint(1);
y(1) = startPoint(2);
h3 = figure;
% Update line points accumulating on previous point
for k = 1 : 100
for i = 2 : lineLength
x(i,k) = x(i - 1,k) + directions(k,1) * i;
y(i,k) = y(i - 1,k) + directions(k,2) * i;
end
%hold the figure and plot the k-th line
hold on;
plot( y(: , k) , x(: , k) , 'r.');
end