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

42 Ansichten (letzte 30 Tage)
Omer hakan Yaran
Omer hakan Yaran am 24 Mai 2022
Bearbeitet: Allen am 24 Mai 2022
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

Antworten (1)

Allen
Allen am 24 Mai 2022
Bearbeitet: Allen am 24 Mai 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 Kommentar
Omer hakan Yaran
Omer hakan Yaran am 24 Mai 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by