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

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

댓글 수: 6

i write some comments but see if it is correct
What is your question? What are you trying to do that you are not able to do?
@Saleh: Please do not bump your question by posting comments, which do not contain new information.
Usually the cause for not getting answers is an unclear question, not that the question is read to rarely.
while(~isreal(R)|| any(R<=0)||(mod(n,2)==1)|| 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,2)==1)
R=input('The number of Resistance should be odd.\nRe-enter
my program is too long but can i post it all here ?
i want help only just to write a comment in every line
comments means using %

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

답변 (1개)

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.

카테고리

도움말 센터File Exchange에서 Powertrain Blockset에 대해 자세히 알아보기

질문:

2022년 12월 6일

편집:

2022년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by