Need Help fixing a for loop for iteration

1 vue (au cours des 30 derniers jours)
Fun Dan
Fun Dan le 28 Avr 2015
Commenté : Star Strider le 28 Avr 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 commentaire
Star Strider
Star Strider le 28 Avr 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

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 28 Avr 2015
In the code you posted, you don’t seem to be changing the value of ‘P’.
  4 commentaires
Fun Dan
Fun Dan le 28 Avr 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 le 28 Avr 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by