# explaining this code for me please it's about making circuit in matlab but i confused here because i want to write comments in every line i have 160 line but i put some

1 view (last 30 days)
Saleh on 6 Dec 2022
Edited: Walter Roberson on 6 Dec 2022
explaining this code for me please it's about making circuit in matlab but i confused here because i want to write comments in every line i have 160 line but i put some if any one will accept to write for me all the comments in this code please
while(~isreal(R)|| any(R<=0)||(mod(n,2)==0)|| any(n<1))
if(~isreal(R)) %Determine whether model parameters or data values are real.
R=input('The values of all Resistance must be real.\nRe-enter values of the Resistance in Ohm,[R1...Rn]=');
n=length(R);
elseif(any (R<=0)) %less or equal zero
R=input('All Resistance should be positive (non-zero) real numbers, check the values and enter again.\nRe-enter values of the Resistance in Ohm,[R1...Rn]=');
n=length(R);
elseif(mod(n,3)==0)
R=input('The number of Resistance should be 2.\nRe-enter values of the Resistance in Ohm,[R1...Rn]=');
n=length(R);
elseif(n<1) %is not less than 1
R=input('The minimum value for n is 1.\nRe-enter values of the Resistance in Ohm,[R1...Rn]=');
n=length(R);
else
break; % it breaks while loop if entered correct resistance according to requirments
end
end %end the while and if statment/loop
Saleh on 6 Dec 2022
my program is too long but can i post it all here ?
i want help only just to write a comment in every line

Jan on 6 Dec 2022
while ~isreal(R) || any(R<=0) || mod(n,2)==0 || any(n<1)
Comment: Repeat until R is a real positive value and n is an odd positive integer.
The comments matching the if and elseif conditions can be found in the following explanations in the input() commands already.
n=length(R);
This line does not need a comment. If a reader knows Matlab, the length() command is trivial.
This is strange: In the while loop you have mod(n,2)==0, in the if condition mod(n,3)==0 and the message tells the user: "The number of Resistance should be 2". Then n==2 would be the correct condition.
So actually this code does not need any further comments, but a bug fix.