I need to graph, in the real model time, the results of subtracting the [i+1] and [i] values over the values in a data set. (Subtraction=[i+1] – [i]).
I prepared an event Timeout triggered, that Occur one 1 year, steps are:
1.- A for loop will be executed only if there are values different than 0, on the i and the i+1 indexes.
2.-The subtraction operation will be performed and the result, with the index, is passed to the empty dataset, that will be used to plot these new values.
3.-The index and the result of the subtraction will be passed to the destination Dataset ( that will be graphed.) The index will increase itself, wainting for the next iteration.
4.- If there is missing some of the pairs values, that needs to be subtracted, the action will be to asign the same already substracted value with the index, later the index will increase itself also.
The events´ body:
int index =0; double resultado =0; // Simulación: llenar la lista con valores del stock al cambiar de año for (int i = 0; i < TFGDS.size(); i++) { if (i < TFGDS.size() - 1 && TFGDS.getY(i) != 0.0 && TFGDS.getY(i + 1) != 0.0) { resultado = TFGDS.getY(i+1)-TFGDS.getY(i); // Realizando la resta TFGValorAnual.add(index, resultado); // Asignando valores index++; // Aumentando el valor para la proxima asignacion }else{ TFGValorAnual.add(index, resultado); // asignando el valor anterior index++; // Aumentando el valor para la proxima asignacion } };
The result: the event can assign only 2 indexes with values as zero, to the destination dataset, while the origin dataset is growing .
I can’t figure it out where the mistake is.
3
I stopped using for loop. Instead the event will occur every 2 years. This will make my new dataset the middle size as the original one. But this will work for plot in real time.
I prepared a variable (i) that will be increased every time change. This will be the dataset guide point to make the subtraction.
The subtraction formula needs to be
resultado = TFGDS.getY(i-1)-TFGDS.getY(i-2);
for being sure the event is using the dataset existing values, as the event is occuring every 2 years.
Thank you all for making my brain more creative.