How to Store a Series of Column Vectors from a for Loop in a Matrix
14 次查看(过去 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!