Doubt in matlab coding

1 Ansicht (letzte 30 Tage)
Ancy S G
Ancy S G am 17 Mär. 2022
Kommentiert: Mathieu NOE am 29 Mär. 2022
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?

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 17 Mär. 2022
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 Kommentare
Ancy S G
Ancy S G am 29 Mär. 2022
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 am 29 Mär. 2022
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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by