How to correct the code?

조회 수: 3 (최근 30일)
Ancy S G
Ancy S G 2022년 3월 1일
댓글: Ancy S G 2022년 3월 17일
phis=3;phib=8;
cons=-.95:0.5:10;% for plotting
Eg=[-2.9583 5.2519 -6.5456 5.2455 -0.4883 -7.0614];% for 6 prosumers
xi=[1 1 1 1 1 1];
for n=1:1:6
if Eg(:,n)>=cons
cons=xi/phis-1;
elseif Eg(:,n)<cons
cons=xi/phib-1;
else
end
end
plot(cons,'*')
xlabel('No of prosumers')
ylabel('consumption')
I have to plot two dfiiferent values for two condition,But I got the same values for two conditions.Is any there any mistake in the code?
  댓글 수: 1
KSSV
KSSV 2022년 3월 1일
Dimensions of Eg and cons are different....?

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

채택된 답변

Arif Hoq
Arif Hoq 2022년 3월 1일
you are comparing [Eg(:,n)>=cons] with an array where Eg(:,n) neither greater nor smaller.
see in index 2 of Eg, 5.2519 > 0.5 and 5.2519 < 10. that's why you are getting one single value that is "else" value.
if your variable "cons" and Eg iare same dimension array, then
phis=3;
phib=8;
% cons=-.95:0.5:10;% for plotting
% cons= -8;
cons= [-3,8,-7,6,-2,-8];
Eg=[-2.9583 5.2519 -6.5456 5.2455 -0.4883 -7.0614];% for 6 prosumers
xi=[1 1 1 1 1 1];
C=zeros(1,6);
[idx ]=find(Eg >= cons);
B=xi/phis-1;
B1=B(idx);
[idx2]=find(Eg < cons);
D=xi/phib-1;
D1=D(idx2);
C(idx2)=D1;
C(idx)=B1
C = 1×6
-0.6667 -0.8750 -0.6667 -0.8750 -0.6667 -0.6667
plot(C,'o')
xlabel('No of prosumers')
ylabel('consumption')
  댓글 수: 1
Ancy S G
Ancy S G 2022년 3월 17일
Thank you sir

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by