Error when adding values to array in loop

I'm trying to add the mean and standard deviation values of a timeseries in a loop to the proper arrays, however i am running into the same error in the multiple ways i'm trying to do it. Here's the code:
for i=31:30:length(TotalReadingsB)
MediaMatriz = [MediaMatriz mean(TotalReadingsB(i-30:i))] %Média de cada mês
SMatriz = [SMatriz std(TotalReadingsB(i-30:i))] %Desvio padrão de cada mês
end
The series contains data for a year and the objective is to collect the the aboce mentioned valued monthly.
This results in the fallowing error:
Dimensions of matrices being concatenated are not consistent.

4 comentarios

Walter Roberson
Walter Roberson el 26 de Abr. de 2018
What size() are MediaMatriz and SMatriz before this loop starts?
They don't initiate with a set size. The final arrays will have size 12 but i want to add the calculated values at the end so i just initiated them like
MediaMatriz;
MediaMatriz;
does not initialize: it causes MediaMatriz to be looked up in the symbol table, gives an error if it is not found, then because of the ';' it discards the output of displaying MediaMatriz .
You need an initialization, something like
MediaMatriz = [];
Guilherme Nogueira
Guilherme Nogueira el 26 de Abr. de 2018
Yes that works! Thanks!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Abr. de 2018

Comentada:

el 26 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by