Doubt in matlab coding
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!