concatenate different matrices with different dimensions
이전 댓글 표시
Hello, I am obtaining 3 matrices with two colums each of then (the first column contains the time and the second column contains the acceleration) that represents the acceleration components of earthquake signals that can be represented as X, Y and Z matrices. So, these matrices may have the following size: X (520x2), Y(480x2) and Z(500x2) as an example. If I want to concatenate the matrices horizontally using this command:
The final size of the matrix (data) should be 520x6 (based on the highest length of colums of the three matrices X,Y and Z). So, zeros should be added at the end of each matrix with lower column size convert Y(480x2) and and Z(500x2) into Y(520x2) and Z(520x2) and then the three matrices be concatenated horizontally to create the matrix data(520x6). Thank you for your help.
채택된 답변
추가 답변 (1개)
Sushma Swaraj
2023년 6월 29일
Hi,
Assuming you have X,Y and Z matrices with different sizes:
% Determine the maximum no.of rows among X,Y and Z
maxRows = max([size(X, 1), size(Y, 1), size(Z, 1)]);
% Create zero matrices to match the no.of rows
Y_zeros = zeros(maxRows, size(Y, 2));
Z_zeros = zeros(maxRows, size(Z, 2));
% Assign the original data to the zero matrices
Y_zeros(1:size(Y, 1), :) = Y;
Z_zeros(1:size(Z, 1), :) = Z;
% Concatenate X,Y_zeros and Z_zeros horizontally
data = horzcat(X, Y_zeros, Z_zeros);
Hope it helps!
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!