Need Help fixing a for loop for iteration

1 visualización (últimos 30 días)
Fun Dan
Fun Dan el 28 de Abr. de 2015
Comentada: Star Strider el 28 de Abr. de 2015
Hi,
I have the following code but it is not giving me the values I want. The loop is not working. Basically, I want the variables J1, J2, J3, J4 and J5 calculated from each coordinates of Mx and My which is used to calculate P in an existing Simscape file. The first value of Length is 500 (with an increment of 10) and Prod_Length = J5-Length.
If P > 6000, then the next values of J1, J2, J3, J4, J5, Length and Prod_Length are calculated and P checked. This process is to go on until P < 6000.
The issue I am having is - it's only calculating my P based on the first values of Length and Prod_Length - without considering the increment of 10 for Length.
#1 for Mx = 50:50:500;
#2 for My = 50:50:400;
#3 %
#4 J1 = [sqrt((Mx-100)^2+(My-20)^2)];
#5 J2 = [sqrt((Mx-20)^2+(My-150)^2)];
#6 J3 = [sqrt((Mx-50)^2+(My-450)^2)];
#7 J4 = [sqrt((Mx-150)^2+(My-450)^2)];
#8 J5 = [sqrt((Mx-7000)^2+(My-200)^2)];
#9 %
#10 %%I have a simscape file that runs with the mfile to check the value of P
#11 while P > 6000
#12 Length = Length + 10
#13 Prod_Length = J5 - Length;
#14 end
#15 end
#16 end
Thank you
  1 comentario
Star Strider
Star Strider el 28 de Abr. de 2015
Fun Dan’s additional Comment (moved from an Answer Comment):
The mfile is linked to an external Simulink file which calculates 'P' based on the different values of J1, J2, J3 J4 and J5. My issues is getting the loop to work for the stated condition. Thanks

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 28 de Abr. de 2015
In the code you posted, you don’t seem to be changing the value of ‘P’.
  4 comentarios
Fun Dan
Fun Dan el 28 de Abr. de 2015
The mfile is linked to an external Simulink file which calculates 'P' based on the different values of J1, J2, J3 J4 and J5. My issues is getting the loop to work for the stated condition. Thanks
Star Strider
Star Strider el 28 de Abr. de 2015
Simulink is not an area of my expertise. I added Simulink to the ‘Products’ tags, and your latest Comment as a Comment to your original Quesiton. I will delete my Answer (and all the subsequent Comments to it) in a few minutes, since I can’t help.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by