Need Help fixing a for loop for iteration

조회 수: 1 (최근 30일)
Fun Dan
Fun Dan 2015년 4월 28일
댓글: Star Strider 2015년 4월 28일
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
Star Strider
Star Strider 2015년 4월 28일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2015년 4월 28일
In the code you posted, you don’t seem to be changing the value of ‘P’.
  댓글 수: 4
Fun Dan
Fun Dan 2015년 4월 28일
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 2015년 4월 28일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by