Doubt in matlab coding
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
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
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!