Assigning value to a variable.

34 views (last 30 days)
Heya :)
Heya :) on 15 Oct 2020
Commented: Star Strider on 16 Oct 2020
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);

Accepted Answer

Star Strider
Star Strider on 15 Oct 2020
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.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!