How to put 8 variables into a single matrix?

2 vues (au cours des 30 derniers jours)
Devendra
Devendra le 1 Juil 2023
Réponse apportée : Nupur le 1 Juil 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

Réponse acceptée

Animesh
Animesh le 1 Juil 2023
Modifié(e) : Animesh le 1 Juil 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.

Plus de réponses (1)

Nupur
Nupur le 1 Juil 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));

Catégories

En savoir plus sur Logical 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