how to store coordinate values xy[] for randomly generate point

조회 수: 2 (최근 30일)
tumpa pal
tumpa pal 2020년 5월 15일
댓글: tumpa pal 2020년 5월 22일
for i=1:NumOfNodes
S(i).xd=rand(1)*xm;
S(i).yd=rand(1)*ym;
end
from this given code I can store coordinate of randomly generate point in matrix format but
How could I store coordinate of randomly generate point xy=[3.7739 88.5168; ........]; like this format .

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 5월 15일
Try one-liner, no loop.
xy=[xm*rand(NumOfNodes,1), ym*rand(NumOfNodes,1)]

추가 답변 (1개)

Turlough Hughes
Turlough Hughes 2020년 5월 15일
The format you used (based on the code you provided) is a structure and the format you are looking for is an array. To generate an N by 2 array as you specified you can do the following:
N = 20;
xm = % some value
ym = % some value
xy = rand(N,2).*[xm ym];
  댓글 수: 1
tumpa pal
tumpa pal 2020년 5월 22일
suppose xy = 100*rand(n,2);
after few operation the value of x y cordinate value will be changed .
how could I implement into my MATLAB code?
thanks in advance

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by