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

1 visualización (últimos 30 días)
mukesh kumar
mukesh kumar el 15 de Mzo. de 2018
Comentada: Bob Thompson el 16 de Mzo. de 2018
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 comentarios
Bob Thompson
Bob Thompson el 15 de Mzo. de 2018
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 el 15 de Mzo. de 2018
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

Iniciar sesión para comentar.

Respuestas (1)

Bob Thompson
Bob Thompson el 15 de Mzo. de 2018
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 comentarios
mukesh kumar
mukesh kumar el 16 de Mzo. de 2018
Editada: mukesh kumar el 16 de Mzo. de 2018
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 el 16 de Mzo. de 2018
Which line does it show the error on?

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by