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

6 次查看(过去 30 天)
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 个评论
James Water Bird
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
Saleh 2022-12-6
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 个)

Jan
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.

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by