a program that moves over matlab and bounces back at a certain point

Asked 2 years ago, Updated 2 years ago, 80 views

I have a question about matlab.

in an area Place the terminal randomly between (1,5) and (1,18) sides and
I want to move it up and down.

Therefore, the location of the wireless terminal is set to (xi, yi), and
Increase the value of y by 1 per second
Now, when (1,18) is reached, the value of y is
I would like to make a program that decreases by one and increases the value of y by one when it reaches (1,5).

xi=1;
yi = obj.yi_;
if(yi>=18)
    yi = obj.yi_-1;
elseif(yi<=5)
    yi = obj.yi_+1;
end

I have programmed with
but this program does not include
It stops at (1,18) ever since it reached (1,18).

How can I change the program to work well?

matlab

2022-09-29 22:46

1 Answers

Since I don't have a Matlab running environment at hand, I will answer any issues that I can understand from reading the code.Please point out any mistakes.

 if(yi>=18)
yi = obj.yi_-1;
elseif(yi<=5)
yi = obj.yi_+1;
end

If you chew this part of the code, you can see that obj.yi_ is reduced by 1 if the value obj.yi_ is greater than or equal to 18, i is increased by 1 if the value obj.yi_ is less than or equal to 5, and does nothing else.

Therefore, as far as the code is concerned, there are the following problems:

  • Nothing happens when
  • 6<=obj.yi_<=17
  • obj is not known how is defined, so there is no way to indicate the correct implementation
    • It stops at (1,18) ever since it reaches (1,18), so is there an implementation that moves up and down somewhere?
  • The current direction of movement is not indicated.
    • There is no problem with the above two if there is an implementation somewhere that is not mentioned in this question.However, , which stops at (1,18) ever after reaching the subject, (1,18), is clearly due to the fact that the current direction of movement remains positive without bouncing back on the wall.
  • It stops at (1,18) ever since it reaches (1,18), so is there an implementation that moves up and down somewhere?
  • There is no problem with the above two if there is an implementation somewhere that is not mentioned in this question.However, , which stops at (1,18) ever after reaching the subject, (1,18), is clearly due to the fact that the current direction of movement remains positive without bouncing back on the wall.

You might want to introduce a variable called v that represents the speed and convert it backwards when it bounces back into the wall.In the future, you will be able to change the speed and specify the modulus of wall elasticity.

v=1;
xi = 1;
yi = obj.yi_;
if(yi>=18)
yi = obj.yi_-1;
v=-v;
elseif(yi<=5)
yi = obj.yi_+1;
v=-v;
end


2022-09-29 22:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.