Effacer les filtres
Effacer les filtres

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

25 vues (au cours des 30 derniers jours)
Omer hakan Yaran
Omer hakan Yaran le 24 Mai 2022
Modifié(e) : Allen le 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

Réponses (1)

Allen
Allen le 24 Mai 2022
Modifié(e) : Allen le 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 commentaire
Omer hakan Yaran
Omer hakan Yaran le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by