Borrar filtros
Borrar filtros

How to put 8 variables into a single matrix?

11 visualizaciones (últimos 30 días)
Devendra
Devendra el 1 de Jul. de 2023
Respondida: Nupur el 1 de Jul. de 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

Respuesta aceptada

Animesh
Animesh el 1 de Jul. de 2023
Editada: Animesh el 1 de Jul. de 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.

Más respuestas (1)

Nupur
Nupur el 1 de Jul. de 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));

Categorías

Más información sobre Creating and Concatenating Matrices 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!

Translated by