Doubt in matlab coding

조회 수: 1 (최근 30일)
Ancy S G
Ancy S G 2022년 3월 17일
댓글: Mathieu NOE 2022년 3월 29일
I want to get the output of this concept:
that is, if Eg>Egm
then output is Ns =5,6,7
Otherwise if Eg<Egm
output as Nb=1,2,3
else Nsb=4
I want to get corresponding N values for each condition.How to get this?
a=3;b=8;
Eg=[50 100 150 175 200 250 300];
Egm=Mean(Eg);
P=[20 15 10 5 1 0.5 0.1]
for N=1:1:7
if Eg>Egm
% output as Ns
elseif Eg<Egm
% output as Nb
else
%output as Nsb
end
end
Based on this values,I want to compute following
Xs=(P(n)/a)-1;But value of P(n) is taken ony the value corresponding to Ns,that is 1,0.5,0.1
Xb=(P(n)/b)-1;But value of P(n) is taken ony the value corresponding to Nb,that is 20,15,10
Xsb=Eg; For the value Nsb
How this concept can be coded?

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 3월 17일
hello
here you are my friend, without a for loop
a=3;b=8;
Eg=[50 100 150 175 200 250 300];
Egm=mean(Eg);
P=[20 15 10 5 1 0.5 0.1];
m = length(Eg);
Ns = find(Eg>Egm);
Nb = find(Eg<Egm);
Nsb = (1:m);
Nsb(Ns) = [];
Nsb(Nb) = [];
Xs=(P(Ns)/a)-1;
Xb=(P(Nb)/b)-1;
Xsb=Eg(Nsb);
  댓글 수: 12
Ancy S G
Ancy S G 2022년 3월 29일
Thank you for your valuable effort.
Sir,it's the same code.
Here Xs,Xb,Xsb in the above code,I just put it as X for all.
I want to stop this iterative process until the error between previous iterative value and new value converges nearly to zero.That is the value of X in this code.
My doubt is how to make this code as a iterative computation and the know the values of X after each iteration.
Mathieu NOE
Mathieu NOE 2022년 3월 29일
hello again
I am not sure to understand how you want to have the X by iteration
the previous code (see below) is based on conditional statements (if, else,...) and I don't see how you can replace that logic with an iteration on X
maybe you can help me clarify this point
a=3;b=8;
Eg=[50 100 150 175 200 250 300];
Egm=mean(Eg);
P=[20 15 10 5 1 0.5 0.1];
Ns = [];
Nb = [];
Nsb = [];
for ci=1:length(Eg)
if Eg(ci)>Egm
% output as Ns
Ns = [Ns ci];
elseif Eg(ci)<Egm
% output as Nb
Nb = [Nb ci];
else
%output as Nsb
Nsb = [Nsb ci];
end
end
Xs=(P(Ns)/a)-1;
Xb=(P(Nb)/b)-1;
Xsb=Eg(Nsb);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by