Overwrite a CELL-ARRAY
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone!
I have a BIG problem, and I dont know how to fix it! I have 3 for-loops (iside each other), the final result should be written in a cell array, every column in each cell is written loop by loop, I mean, in total I have 4 cells (thats works perfectly). The first 1 columns of each cell are written perfectly, but when its time to calculate the second column of the first cell, the code overwrite the first column of the first cell with the first column of the 4th cell, and that happens successively.
I copy a part of the code
for j = 1: predecir
for i=1:puntos_grilla
for itera=1:cantidad_de_iteraciones
variable = vtec_logaritmico{i};
T = tonndata(variable(ndiaini+j:delta-1+j,1),false,false);
.
.
.
.
.
.
.
vtec_pronosticado(itera,j)= exp(yys(end))*vtec_intervalo(ivtec+j-1,1);
vtec_final{1,i} = vtec_pronosticado ; %Cell-Array con n cantidad de columnas como n iteraciones tengamos
end
end
end
Cold you give me a hand?
Do you need all the code and the data?
2 个评论
Geoff Hayes
2019-7-1
Dini - you may need to show more of your code. Also, with this line
vtec_final{1,i} = vtec_pronosticado
shouold j be used? Or should this be in another loop? As it doesn't seem to make sense that we want to overwrite this value with vtec_pronosticado on each iteration of this inner loop.
回答(1 个)
Guillaume
2019-7-1
As Geoff said, at the moment this line
vtec_final{1,i} = vtec_pronosticado2 ;
doesn't make much sense. We have:
for i=1:puntos_grilla
for itera=1:cantidad_de_iteraciones
%...
vtec_pronosticado2 = ...
vtec_final{1,i} = vtec_pronosticado2;
end
end
When i=1, itera=1, you calculate vtec_pronosticado2 and put that into vtec_final{1, 1}
Then i=1, itera = 2, you calculate another vtec_pronosticado2 but put that in the same vtec_final{1, 1}, overwriting the value you've written when itera was 1.
And so on, for i=1, itera=3:cantidad_de_iteraciones. In effect, the only value that matters is the last iteration of itera when it's equal to cantidad_de_iteraciones. The above could be rewritten to
for i=1:puntos_grilla
itera = cantidad_de_iteraciones; %only the last iteration matters
%...
% vtec_pronosticado2 = ...
vtec_final{1,i} = vtec_pronosticado2;
end
without changing the behaviour. But I doubt that's what you wanted. Problably, itera should be part of the indexing of vtec_final.
Also. vtec_final should be predeclared instead of growing it in a loop. Knowing the size that it's supposed to finish with would also hint at what is wrong with the above.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Modeling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!