한 방향으로 한 라인에 다음 코드를 사용해보십시오 : - :
%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
첫 번째 부분을 보내 주셔서 감사합니다. 그러나 두 번째 부분에서는 100 번 바뀌고 싶은 줄의 방향이 아니라 전체 벡터의 방향입니다. 나는 같은 그래프에서 100 개의 서로 다른 무작위 방향을 가진 100 개의 벡터를 원한다. 그러나 선 길이는 변하지 않는다. 길이는 중요하지 않습니다 ... 그리고 그것은 다음 단계에 대한 내 문제입니다! – user1936545
각각 다른 방향으로 여러 줄에 대한 답의 새로운 세 번째 부분을 시도하십시오. –