For loop taking only last column
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Bjorn Gustavsson
2021년 2월 2일
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?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!