Filter löschen
Filter löschen

How to put 8 variables into a single matrix?

11 Ansichten (letzte 30 Tage)
Devendra
Devendra am 1 Jul. 2023
Beantwortet: Nupur am 1 Jul. 2023
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

Akzeptierte Antwort

Animesh
Animesh am 1 Jul. 2023
Bearbeitet: Animesh am 1 Jul. 2023
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.

Weitere Antworten (1)

Nupur
Nupur am 1 Jul. 2023
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));

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