lundi 4 décembre 2017

Issue in loop logic, testing for condition with for loop instead of while loop

Simply Looping until condition is met

I have Desired value = 10 and I make a loop that performs action means It makes calculations and runs the loop unless or until received value is within acceptable range.

value_desired = 10

received Value = 5 ; from code

Unless or until received value is with in acceptable range (10+1 = 11 ; 10-1 = 9) I should run the loop and perform the actions.

Question:

I have an issue in the else part

If my logic goes to the else part then I want my program to perform the tasks of else part and go to

J = out  + 4;
received_value_J = J;

then calculate a new value and perform the task unless it satisfies

if (ii == 1)
value_finalized =  received_value_J;

I want to use for loop for this. Is it possible?

value_desired = 10 
acceptable_limit_1 = value_desired + 1
acceptable_limit_2 = value_desired - 1
acceptable_limit_upper_range = [value_desired :0.01: acceptable_limit_1];
acceptable_limit_lower_range = [acceptable_limit_2 : 0.01 : value_desired ];

delta = 0.1;
out =  1 

J = out  + 4;
received_value_J = J;

ii =  (received_value_J >= acceptable_limit_lower_range(1) & ... 
       received_value_J <= acceptable_limit_upper_range(end) );

while ((ii ~= 1 ))   
    % Right now using this with while loop but i have commented it to explain the question
    % J = out  + 4;
    % received_value_J = J; 
    %  Range Limit    
    ii =  (received_value_J >= acceptable_limit_lower_range(1) & ...
           received_value_J <= acceptable_limit_upper_range(end) );

    difference_signal = (value_desired -  received_value_J );

    if (ii == 1)
        value_finalized =  received_value_J;    
    else (ii ~= 1)
        Add = delta*difference_signal;
        out =  received_value_J + Add ;    
    end
end

Aucun commentaire:

Enregistrer un commentaire