remove rows from a cell array until condition doesn't met

조회 수: 1 (최근 30일)
mukesh kumar
mukesh kumar 2018년 3월 15일
댓글: Bob Thompson 2018년 3월 16일
U=find(AGe<CONS_T3);
lets take U=11 then remove rows from CNSSS{11,1} and update CONS_T3=(CONS_T3-removed row) each time until the CONS_T3<=AGe. simillary do for all U values. I tried this but can not get results...(CONS_T3 is sum of CNSSS of all rows)
for j=1:length(U)
CONS_T3=CONS_T3-CNSSS{U(j),1}(1,:);
CNSSS{U(j),1}(1,:)=[];
if CONS_T3(U(j))>AGe(U(j))
CONS_T3=CONS_T3-CNSSS{U(j),1}(1,:);
CNSSS{U(j),1}(1,:)=[];
end
end
  댓글 수: 2
Bob Thompson
Bob Thompson 2018년 3월 15일
What type of variables are AGe, CONS_T3, CNSSS, and U?
It looks like the if statement isn't really doing a whole lot, since you just have the previous commands repeated again.
mukesh kumar
mukesh kumar 2018년 3월 15일
AGe(size 1*24) aggregator energy and CONS_T3(1*24 size) total energy consumption in each hours that is the sum of all loads CNSSS in each hours,if AGe<CONS_T3 then remove load one by one and update CONS_T3 until AGe>=CONS_T3. thanks for support

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

답변 (1개)

Bob Thompson
Bob Thompson 2018년 3월 15일
If you're trying to just get rid of all U rows then you will want to use something more like this:
U=find(AGe<CONS_T3);
for j=1:length(U)
if U(j) == 1; % Check to see if U(j) == 1 because matrixing from 1:0 doesn't make sense
CONS_T3 = CONS_T3(2:end,:); % Remove first row if first row is bad
else
CONS_T3=vertcat(CONS_T3(1:U(j)-1,:),CONS_T3(U(j)+1:end,:)) % There's not real reason to bring CNSSS into this, because all the values of CNSSS are already part of CONS_T3
CNSSS{U(j),1}(1,:)=[]; % You can leave this if you would like, but it's not really necessary
end % U(j) check if
if sum(CONS_T3)>sum(AGe) % If statement to check of AGe is greater than CONS_T3 yet.
break % Break the loop to stop removing elements. If you just want to remove all the elements anyway, then just get rid of this if statement
end % summation check if
end U(j) loop
  댓글 수: 2
mukesh kumar
mukesh kumar 2018년 3월 16일
편집: mukesh kumar 2018년 3월 16일
it shows error of Index exceeds matrix dimensions. all U will be removed when one by one remove rows from CNSSS with updating each time CONS_T3 =cONS_T3-that row. thanks
Bob Thompson
Bob Thompson 2018년 3월 16일
Which line does it show the error on?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by