Assigning value to a variable.

36 Ansichten (letzte 30 Tage)
Heya :)
Heya :) am 15 Okt. 2020
Kommentiert: Star Strider am 16 Okt. 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);

Akzeptierte Antwort

Star Strider
Star Strider am 15 Okt. 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.
  2 Kommentare
Heya :)
Heya :) am 16 Okt. 2020
Thank you!
Star Strider
Star Strider am 16 Okt. 2020
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by