Doubt in matlab coding
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Mathieu NOE
on 17 Mar 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 Comments
Mathieu NOE
on 29 Mar 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);
More Answers (0)
See Also
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!