Assigning value to a variable.

조회 수: 34 (최근 30일)
Heya :)
Heya :) 2020년 10월 15일
댓글: Star Strider 2020년 10월 16일
Please elaborate what is the meaning of following commands. I am confused about assigning values to variables.
x(1)=1;
y(1)=1;
What the following two commands are showing? How do we decide to assign values to variables?
x_rec(1)=x(1);
hx(1)=y(1);

채택된 답변

Star Strider
Star Strider 2020년 10월 15일
Put simply:
x(1)=1; % ‘x’ is an array, with the first element assigned to ‘1’
y(1)=1; % ‘y’ is an array, with the first element assigned to ‘1’
These do similar things:
x_rec(1)=x(1); % ‘x_rec’ is an array, with the first element assigned to ‘x(1)’
hx(1)=y(1); % ‘hx’ is an array, with the first element assigned to ‘y(1)’
How do we decide to assign values to variables?
Assign them using the = operator. (See MATLAB Operators and Special Characters for a full description of it and others.) Decide on how to assign them depending on what you want your code to do. For example ‘x_rec’ may record the value of ‘x(1)’ for later reference. The second line operates the same way. The reason has to do with the code they came from, and what it does.
  댓글 수: 2
Heya :)
Heya :) 2020년 10월 16일
Thank you!
Star Strider
Star Strider 2020년 10월 16일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by