Assigning value to a variable.
15 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!