How to Store a Series of Column Vectors from a for Loop in a Matrix
조회 수: 15 (최근 30일)
이전 댓글 표시
Hello all, I have a large data, I divide the data into different columns with a for loop. For loop is essential since I don't just divide the data into parts, I also manipulate the data.
inxi = [1,2,3,4,5,6,7] => a column vector
ws and step => scalar numbers
i => for loop variable
inxi = labels_win(:,1);
inx(:,i) = inxi-ws*(step-1);
I want the column vector to be stored in the next column at each for iteration like shown below
댓글 수: 0
답변 (1개)
Allen
2022년 5월 24일
편집: Allen
2022년 5월 24일
You can append new column data onto an existing array provided the heights are equal by concatenating the new vector onto the old array.
A % Some original array of data such that. [rows,cols] = size(A);
B = []; % Empty array
for c=1:cols
inxi = A(:,c);
% Some calculations
% inxi = ...
% Recontructing a new matrix from the modified columns
% B(:,c) = [B,inxi];
B = [B,inxi]; % Removed array index from left-hand side of the operation
end
You can also perform calculations directly to various columns of your original array.
B = A; % Copy data to a new variable to preserve the orginal array
B(:,1) = B(:,1)...; some calculation
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!