Assigning value to a variable.

33 visualizzazioni (ultimi 30 giorni)
Heya :)
Heya :) il 15 Ott 2020
Commentato: Star Strider il 16 Ott 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);

Risposta accettata

Star Strider
Star Strider il 15 Ott 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 Commenti
Heya :)
Heya :) il 16 Ott 2020
Thank you!
Star Strider
Star Strider il 16 Ott 2020
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by