How to put 8 variables into a single matrix?

7 次查看(过去 30 天)
I have 8 variables each of them having dimension(65,1). I want to put them in a matrix of dimension(65,8). Please suggest me how to do it using matlab code.
Devendra

采纳的回答

Animesh
Animesh 2023-7-1
编辑:Animesh 2023-7-1
To combine the 8 variables into a matrix of dimension (65,8) in MATLAB, you can use the concatenation operation. Here's an example MATLAB code that demonstrates how to do it
% Example variables
var1 = rand(65,1);
var2 = rand(65,1);
var3 = rand(65,1);
var4 = rand(65,1);
var5 = rand(65,1);
var6 = rand(65,1);
var7 = rand(65,1);
var8 = rand(65,1);
% Combine variables into a matrix
combined_matrix = [var1, var2, var3, var4, var5, var6, var7, var8];
% Display the size of the combined matrix
disp("Size of the combined matrix: " + size(combined_matrix));
In this example, var1 to var8 represent your 8 variables, each having a dimension of (65,1). The combined_matrix is created by horizontally concatenating these variables using square brackets []. The resulting matrix will have a dimension of (65,8).
The size(combined_matrix) function is used to display the size of the combined matrix.

更多回答(1 个)

Nupur
Nupur 2023-7-1
Try the following please:
% Assuming you have eight variables: var1, var2, var3, var4, var5, var6, var7, var8
% Combine the variables into a matrix
combinedMatrix = [var1, var2, var3, var4, var5, var6, var7, var8];
% Alternatively, you can use the horzcat function
% combinedMatrix = horzcat(var1, var2, var3, var4, var5, var6, var7, var8);
% Display the size of the combined matrix
disp(size(combinedMatrix));

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by