필터 지우기
필터 지우기

what is mean by this

조회 수: 3 (최근 30일)
Junaid Qadir
Junaid Qadir 2017년 8월 3일
댓글: Walter Roberson 2023년 7월 25일
S(i).xd=rand(1,1)*xm;

답변 (4개)

ES
ES 2017년 8월 3일
S is an array of structures.
xd is one of the members of the structure (type unknown).
In the given line, member xd of the i'th structure is updated with a random number (generated using rand function) multiplied by xm.
  댓글 수: 2
Junaid Qadir
Junaid Qadir 2017년 8월 3일
please clear my concept with suitable Example.
Junaid Qadir
Junaid Qadir 2017년 8월 3일
편집: Walter Roberson 2017년 8월 3일
i can't understand the following code.
for i=1:1:NumberOfNodes
S(i).xd=rand(1,1)*width;
S(i).yd=rand(1,1)*depth;
S(i).E=Eo;
S(i).R=Eo;

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


Star Strider
Star Strider 2017년 8월 3일
It sets the ‘xd’ field of the i-th element of structure ‘S’ to rand times a variable called ‘xm’. The ‘(1,1)’ argument to rand is redundant, since a single call to rand returns a single random scalar value.
For more information, see the documentation on Structures (link).
  댓글 수: 4
Star Strider
Star Strider 2017년 8월 3일
Please see the documentation on structures that I linked to in my Answer.
It explains their use and addressing much better than I can.
Jan
Jan 2017년 8월 3일
@Junaid Qadar: The forum is not the best location to clarify the basics of Matlab. Please read the documentation of the concerned command and the Getting Started chapters for this. See also https://matlabacademy.mathworks.com/ -> Onramp

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


ES
ES 2017년 8월 4일
편집: ES 2017년 8월 4일
There are a number of nodes in your problem - denoted by "NumberOfNodes".
xd, yd, E, R are properties of each of these nodes. The properties of the nodes are stored in a array of structures in this case. where S(1) denotes the properties of Node 1 and so on.
The piece of code you have put, sets the properties for all the nodes iteratively.
xd is set to random number * width;
yd is set to random number * depth;
E is set to E0
R is set to R0

Abilasha
Abilasha 2023년 7월 25일
kindly explain this code, its in leach protocol matlab code
figure(1);
for i=1:1:n
S(i).xd=rand(1,1)*xm;
S(i).yd=rand(1,1)*ym;
S(i).G=0;
S(i).type='N';
temp_rnd0=i;
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 7월 25일
xd is set to a random number times xm. In other words the x coordinate is set to a random position in the range 0 to xm (maximum x). Likewise the y coordinate is set to a random location in the range 0 to ym.
(Note: the results can never be exactly 0 or exactly xm or ym because of the details of rand().)
You are generating a random position inside a rectangle.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by