How to write and run while loop in app design?

C= app.CollectionEditField.Value;
S= app.ServingEditField.Value;
app.cycle=0;
cycle_t=app.cycle;
app.FC=0;
F_C=app.FC;
app.F=0;
F_1 =app.F;
SC= S;
while F_C<=double(SC-0.000001))
F_1= double(S*C);
S= double(S-F_1);
F_C= double(F_C+F_1);
Fo= F_C;
cycle_o= (cycle_t+1);
end
app.CycleEditField.Value= cycle_o;
app.FInalCollectionEditField.Value= Fo;

8 件のコメント

dpb
dpb 2021 年 6 月 11 日
The posting could stand some context and explanation of just what is the problem, but...
C= app.CollectionEditField.Value;
S= app.ServingEditField.Value;
are both text values; I think you need a str2double() here and undoubtedly an error handler to catch any failure in the conversion.
That's the crystal ball talking lacking any other information to go on...
Shabaz Khan
Shabaz Khan 2021 年 6 月 11 日
These are numeric edit field box. So, the number what I am providing its passing. SO in that case there are no issue.
dpb
dpb 2021 年 6 月 11 日
So then is there a question here?
Shabaz Khan
Shabaz Khan 2021 年 6 月 11 日
When I am applying S and C value it is going inside of the while loop and showing the cycle number and Fo. But this result is for one cycle. Not for the while loop condition.
Cris LaPierre
Cris LaPierre 2021 年 6 月 11 日
編集済み: Cris LaPierre 2021 年 6 月 11 日
It sounds like your while loop is running, but just not the way you expected. However, without some actual values, we can only guess what is happening. Could you supply what the initial and final values of S, C, cycle_o and Fo should be?
Shabaz Khan
Shabaz Khan 2021 年 6 月 14 日
Example: if S=15 and C=0.02 than cycle_o will 704 and Fo will 15.
dpb
dpb 2021 年 6 月 14 日
F_C=0;
cycle_t=0;
S=15;
C=0.02;
SC=S;
while F_C <=SC-0.000001
F_1= S*C;
S= S-F_1;
F_C= F_C+F_1;
Fo= F_C;
cycle_o=cycle_t+1;
end
>> cycle_o
cycle_o =
1
>> F_C
F_C =
15.0000
>> SC
SC =
15
>>
I have no klew what you're trying to do here, but your first line in the while construct sets F_1 to the S*C product and then the control variable F_C is set to F_C+F_1 which is F_1 since F_C is initialized to zero. Thus, the inequality
F_C <= SC-eps
fails and the loop terminates.
Shabaz Khan
Shabaz Khan 2021 年 6 月 14 日
Try this in command window. You will see cycle number is showing 860.
FC=0;
C=0.02;
cycle=0;
>> S=35;
>> SC=S;
F=0;
while FC <=SC-0.000001
F= S*C;
S= S-F;
FC= FC+F;
cycle=cycle+1;
end

サインインしてコメントする。

回答 (1 件)

Shadaab Siddiqie
Shadaab Siddiqie 2021 年 6 月 15 日

0 投票

From my understanding you are not able to run while loop in your code. I dont see anything wrong with the loop or with the code that you mentioned in the comment, I would advice you to check if the varaibles
C= app.CollectionEditField.Value;
S= app.ServingEditField.Value;
are as expected.

1 件のコメント

Shabaz Khan
Shabaz Khan 2021 年 6 月 17 日
As I am trying to design the app so, my intension is to apply C and S value using app numerical box. When I will give this value in the box then they will do the calculation using the while loop. And after finishing the the calculation it will show the result in another box. Can you kindly say me, what exactly I have to do for design such app? I am getting the result from the command window but when I am using in app its not working?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

2021 年 6 月 11 日

コメント済み:

2021 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by