How to Store a Series of Column Vectors from a for Loop in a Matrix

57 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Allen
Allen il 24 Mag 2022
Modificato: Allen il 24 Mag 2022
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
  1 Commento
Omer hakan Yaran
Omer hakan Yaran il 24 Mag 2022
thank you for your answer, i see this error when i try that method
% Error using horzcat
% Dimensions of arrays being
% concatenated are not
% consistent.

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices 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