For loop taking only last column

6 visualizzazioni (ultimi 30 giorni)
Davide Martintoni
Davide Martintoni il 31 Gen 2021
Commentato: Adam Danz il 2 Feb 2021
Hi,
I am trying a code that creates two vector columns (36x1) and then store the two columns in a matrix. The problem is that the code is repeating the second column sector when storing it in a vector. I tried several option with the foor loops but the results doesn't change. Matrice is matrix in english if it can help!
for i=1:5:6
%here i start from a big matrix and I take 4 rows for each iteration, all columns
x_kalman_rolling_matrice_for = x_kalman_rolling_matrice(i+2:i+5,1:36);
for i=1:2
%here i take all rows from a matrix, but only the first 36 columns (in second iteration from the 2nd to the 37th column);
regressori_girati_for = regressori_girati(:,i:i+35);
for i=1:36
%here i compute a number given by the transpose of a columns from the x_kalman_rolling_matrice_for, so a row, and I multiply it by a column
fitted_kalman_rolling = transpose(x_kalman_rolling_matrice_for(:,i))*regressori_girati_for(:,i);
fitted_kalman_rolling_matrice(i,1)=fitted_kalman_rolling; %here I put one numnber under the other to create a vector
end
end
for i=1:2
fitted_kalman_rolling_matrice_grande(:,i) = [fitted_kalman_rolling_matrice]; %here I would like the two vector to be written one column after the other
%but printing the results shows me that the code is taking only the second vector
end
end
  10 Commenti
Bjorn Gustavsson
Bjorn Gustavsson il 2 Feb 2021
That was what I always used to (but then my memory went somewhere I didn't follow), but I too often forgot which order I had i, j and k. Now I only rely on remembering the order of the natural numbers, when that goes I figure people will tell me to stop messing up programming?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by