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
Saleh
2022년 12월 6일
Saleh
2022년 12월 6일
Jon
2022년 12월 6일
What is your question? What are you trying to do that you are not able to do?
James Water Bird
2022년 12월 6일
편집: Walter Roberson
2022년 12월 6일
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
Saleh
2022년 12월 6일
답변 (1개)
Jan
2022년 12월 6일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!