How to create a matrix using vectors(columns) from different matrices (in a structure) with different lengths?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
So I have a structure that contain in its different cell a matrix os 2 columns and AROUND 1000 rows each. I want to be able to get the second column of each cell to create a matrix. I tried this using a look with an indexed matrix but it replies an error indicating that the size does not match.
0 comentarios
Respuestas (1)
BhaTTa
el 23 de Jul. de 2024
Here is the code to achieve it:
S = {rand(1000, 2), rand(1000, 2), rand(1000, 2)};
% Number of cells in the cell array
num_cells = numel(S);
% Initialize an empty array to store the second columns
% Assuming all matrices have the same number of rows
num_rows = size(S{1}, 1);
second_columns = zeros(num_rows, num_cells);
% Loop through each cell and extract the second column
for i = 1:num_cells
second_columns(:, i) = S{i}(:, 2);
end
% Display the resulting matrix
disp('Matrix of second columns:');
disp(second_columns);
0 comentarios
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!